Android Studio java.util.zip.ZipException: duplicate entry - android

here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.arefin.lasttrykinvay"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name:'kinvey-android-2.10.5', ext:'aar')
compile 'com.android.support:appcompat-v7:23.1.1'
compile google-http-client-1.19.0.jar
compile google-http-client-android-1.19.0.jar
compile google-http-client-gson-1.19.0.jar
compile google-http-client-jackson2-1.19.0.jar
compile gson-2.1.jar guava-18.0.jar
compile jackson-core-2.1.3.jar
compile java-api-core-2.10.1.jar
compile java-api-core-2.10.5.jar
compile kinvey-android-2.10.5.aar
testCompile 'junit:junit:4.12'
}
And here is the error
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/kinvey/java/AbstractClient$Builder$Option.class
When I remove the
compile 'com.android.support:appcompat-v7:23.1.1'
That above error fixes but other functions dont work properly . Like values/style cant not find
Theme.AppCompat.Light.DarkActionBar
How can I that duplicate entry error ?

Remove the duplicate jars and use only required jar and aar files.

Remove duplicate library dependencies.
Although the OP didn't write this out, if you look at the comments on the original question, you'll see that they have a number of .jar library files in the libs directory, which are all included in the following line:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//...
}
In one of their comments, they list the following files in their libs directory:
google-http-client-1.19.0.jar
google-http-client-android-1.19.0.jar
google-http-client-gson-1.19.0.jar
google-http-client-jackson2-1.19.0.jar
gson-2.1.jar
guava-18.0.jar
jackson-core-2.1.3.jar
java-api-core-2.10.1.jar Duplicate!
java-api-core-2.10.5.jar Duplicate!
kinvey-android-2.10.5.aar
You can clearly see that java-api-core is included twice, once for the 2.10.1 version and once for the 2.10.5 version. The build system isn't smart enough to only bring one of these in, and it shouldn't have to be. The user should tell the build system which libraries to be included and which version of each to include.
By removing the java-api-core-2.10.1.jar file from the libs directory, the error should be resolved.
This might not be the exact problem you're running into but it's likely the result of something similar.
To help avoid these situations, here are a couple of best practices:
1. Don't use compile fileTree....
Instead of hiding away all the .jar files that you're including, explicitly state which files you're compiling under dependencies {}. This will make it easier to see when you have duplicates, conflicts and other issues like this.
2. Use Maven instead of .jar files as much as possible.
Although it wouldn't catch this, by using Maven and putting the same dependency twice with different versions it should only resolve one of those dependencies (I think) and avoid a cryptic error like you're seeing.

Try adding these code to your Gradle.
defaultConfig {
multiDexEnabled true
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
or add this class to your Application Class if you dont have Application class just crate it...
public class SomeApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
MultiDex.install(this);
}
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

Related

Packages from library module not found in main module

I got a project which I imported from Eclipse to Android Studio. In Eclipse everything worked well.
It contains a main module (a project in Eclipse) which uses packages from a library module (library project in Eclipse). Since the migration did not went well, I have created a library module manually and just copied all the source code to the newly created module.
The problem is that the main module doesn't seem to find the packages from the library module and when I rebuild the project I get errors like "package bla bla does not exist".
Here is the main module gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.pointer.mamagoose"
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':linphoneclean')
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile files('libs/firebase-client-android-2.5.0.jar')
compile files('libs/apache-httpcomponents-httpclient.jar')
compile files('libs/apache-httpcomponents-httpcore.jar')
compile files('libs/android-support-v7-recyclerview.jar')
}
linphoneclean is the library module.
The entire project's settings.gradle:
include ':linphoneclean'
include ':tigris'
This is the build.gradle of the library module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.6.2'
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/linphone.jar')
compile files('libs/firebase-client-android-2.5.0.jar')
}
The structure of the library module includes for example folder:
src/main/com/pointer/linphone (and inside there are all the java files with a deceleration of package com.pointer.linphone, Yet I still get an error saying >"package com.pointer.linphone does not exist).
What am I doing wrong?
After fighting with the same issue for hours here is what worked for me.
I've created a fresh project with blank activity, added a library module with a dummy class, defined the dependency. Verified that it works by importing the dummy class in the app. Then I copied all my relevant code from the real project.
My thinking is that it was probably issue with IDE's iml files, since starting from scratch and copying stuff over worked.
See properly source file contains both java folder and res folder,add java files in java packages and res in res folder.Add Activity name in Manifest file see here ,add necessary libraries files in Gradle file.Clean and rebuild the project in the Android studio.
https://developer.android.com/guide/topics/manifest/manifest-element.html
Maybe you can check if the library's AndroidManifest has defined the package correctly, like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.pointer.linphone">

java.util.zip.ZipException with spongycastle LICENSE.class

I am trying to include two different 3rd party libs that both seem to include different versions of Spongy castle. Both are included via compile statements in my build.gradle and one is included as an AAR (#aar) while the other is included as normal.
When I try to compile the debug buildType with these 2 libs (sync doesnt show a problem). I see the following,
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
org/spongycastle/LICENSE.class
Been searching around for how to resolve this issue while keeping both the libraries (as both are needed) but have been unable to find a way to do that. Any help from an advanced Android dev or a gradle expert would be greatly appreciated.
Thanks!
[build.gradle]
apply plugin: 'com.android.application'
repositories {
maven { url 'http://mobile-sdk.jumio.com' }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
packagingOptions {
pickFirst 'org/spongycastle/x509/CertPathReviewerMessages.properties'
pickFirst 'org/spongycastle/x509/CertPathReviewerMessages_de.properties'
}
defaultConfig {
applicationId "com.example.me.license"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile "com.jumio.android:jumio-mobile-sdk:1.9.0#aar"
compile 'com.worldpay:cse-android-sdk:1.0.2'
}
This is what happens if developers include their dependencies directly. The bad guy here is jumio-mobile-sdk. This package includes classes of com.madgag.spongycastle directly, instead of specifying them in a pom as it should be done.
Luckily for you, the other package is set up correctly, so you should be able to exclude spongycastle from it:
compile ('com.worldpay:cse-android-sdk:1.0.2'){
exclude group: 'com.madgag.spongycastle'
}
Now imagine both packages would've included the classes directly. The would've been no other possibility then to manually edit the files. This is why I hate it if someone does what the guys of jumio are doing. If you have the contacts, tell them to prepare their package for dependency systems, so this problem won't arise again.

Android :app:transformClassesWithJarMergingForDebug FAILED - ZipException: duplicate entry

Sorry if I asked a duplicate question, but I couldn't find a solution for this error. I surfed around stackoverflow,gradle site, android blogs, google search but there wasn't a working solution for several hours. I'm an android beginner so I not sure if I have missed something in other posts.
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.1.'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
compile 'com.android.support:recyclerview-v7:22.2.1.'
compile 'com.android.support:cardview-v7:22.2.1.'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.pnikosis:materialish-progress:1.7'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile files('libs/android-support-v4-22.2.1.jar')
compile files('libs/applovin-sdk-6.0.1.jar')
compile files('libs/appodeal-1.13.1.jar')
compile files('libs/chartboost-5.2.0.jar')
compile files('libs/my-target-4.0.13.jar')
compile files('libs/unity-ads-1.4.7.jar')
}
The project was working fine until I add some libs from appodeal (those compile file lines). I have tried to build the project but gradle gave the errors.
:app:transformClassesWithJarMergingForDebug'.
com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/widget/RecyclerView$ItemDecoration.class
There are also 2 more error of the same exception about duplicate entry- not sure why I got them: android/support/v4/PrintKitKat.class and android/support/multidex/MultiDex$V14.class.
I tried to upgrade gradle, invalidate and restart to clear cache, omit dependencies then rebuild/clean project, find potential duplicate module to exclude, and search projects for those .class but I found no duplication.
You can test putting this on root of directory in the Terminal
./gradlew clean

Warnings in libraries during signing app

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.hello"
minSdkVersion 9
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/bolts-android-1.2.0.jar')
compile files('libs/facebook.jar')
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:support-v4:22.0.0'
compile('com.crashlytics.sdk.android:crashlytics:2.4.0#aar') {
transitive = true;
}
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0#aar'
compile project(':gcmv')
compile 'com.android.support:design:22.2.0'
}
Today when i am signing my app with a proguard it show too much warning in my libraries.
so because of warning i am unable to generate my signed apk file.
So is there any way to use "dontwarn" in my gradle file.
It seems that you are using picasso library.
Try to add this line in your proguard file. ( proguard-rules.pro in your app module )
-dontwarn com.squareup.okhttp.**
As per the ProGuard documentation:
The standard Android build process automatically specifies the input
jars for you. Unfortunately, many pre-compiled third-party libraries
refer to other libraries that are not actually used and therefore not
present. This works fine in debug builds, but in release builds,
ProGuard expects all libraries, so it can perform a proper static
analysis. For example, if ProGuard complains that it can't find a
java.awt class, then some library that you are using is referring to
java.awt. This is a bit shady, since Android doesn't have this package
at all, but if your application works anyway, you can let ProGuard
accept it with "-dontwarn java.awt.**", for instance.
As stated, if it works well in debug, you can use -dontwarn as a class filter:
Specifies not to warn about unresolved references and other important
problems at all. The optional filter is a regular expression; ProGuard
doesn't print warnings about classes with matching names. Ignoring
warnings can be dangerous. For instance, if the unresolved classes or
class members are indeed required for processing, the processed code
will not function properly.

Android studio source code share by local aar

I'd like to share my source code among different projects through aar. Current version of Android studio is able to generate aar files automatically for library module. But I have a few issues:
How to output aar files to specific folder?
Currently the output is in build/outputs/aar folder. Can I move the files automatically once the compilation has been finished.
The dependencies in library module is not inherited by app module. For example:
My library module (build.gradle):
apply plugin: 'com.android.library'
......
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.code.gson:gson:2.2.4'
}
My app module:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
flatDir {
dirs 'myaarfolder'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.company.appid"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile(name:'mylib-release', ext:'aar')
}
I got an error something like:
Error:(3, 35) Error: Package com.google.gson.annotations not exist
I have to add compile 'com.google.code.gson:gson:2.2.4' in the dependency of my app module (build.gradle)
Any idea? Thanks
AAR files don't have their dependencies baked into them, so if you're including a bare AAR like this, you'll need to manually add dependencies in the parent module. To do what you want you'd need to package the AAR into a Maven artifact and specify its dependencies in the POM. A quick search of Google reveals this link, which looks like it's for an older version of the Android Gradle plugin, but it might get you going, or you can do your own searching for a better resource:
http://www.vandalsoftware.com/post/52468430435/publishing-an-android-library-aar-to-a-maven
If you want to manipulate of your output files, you can take inspiration from this question, which renames outputs:
Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl
Essentially it involves a block of build script that looks like this:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, /* calculate new path here */)
}
}

Categories

Resources