Commons-Io Duplicate Entry Error Using Robospice and Android Studio - android

I've been working on the following issue for several hours, but haven't come up with a way to solve my problem. I've tried the following fixes from Stack Overflow (Android Studio update to 1.0 corrupts MultiDex and Duplicate Zip Entry after Gradle Plugin v0.13.1) but neither one of them worked.
I am getting the following error when trying to build my program:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: org/apache/commons/io/CopyUtils.class
The error seems to indicate that commons-io is being included twice in the build process
I am using Android Studio and Gradle to include multiple Robospice dependencies. This is the dependencies section of my Gradle build file:
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile'com.google.api-client:google-api-client-android:1.19.0'
// You must install or update the Google Repository through the SDK manager to use this dependency.
// The Google Repository (separate from the corresponding library) can be found in the Extras category.
//compile 'com.google.android.gms:play-services:4.3.23'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.jakewharton:butterknife:${butterknifeVersion}"
compile 'com.sun.jersey:jersey-bundle:1.8'
compile 'com.google.code.gson:gson:2.3'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'
compile ('com.octo.android.robospice:robospice:1.4.14'){
exclude module: 'commons-io'
exclude group: 'commons-io'
}
compile ('com.octo.android.robospice:robospice-spring-android:1.4.14'){
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile ('com.octo.android.robospice:robospice-google-http-client:1.4.14'){
exclude module: 'xpp3'
exclude group: 'stax'
}
compile 'org.scribe:scribe:1.3.5'
compile files("$buildDir/native-libs/native-libs.jar")
}
Using the "gradlew -q dependencies app:dependencies" command to view the project's dependency tree indicates that com.octo.android.robospice:robospice:1.4.14 is dependent on the commons-io library. Here is the relevant snippet of the project dependency tree:
+--- com.octo.android.robospice:robospice:1.4.14
| \--- com.octo.android.robospice:robospice-cache:1.4.14
| +--- org.apache.commons:commons-lang3:3.3.2
| \--- org.apache.commons:commons-io:1.3.2
| \--- commons-io:commons-io:1.3.2
The dependency is still listed even though I excluded commons-io from all Robospice related dependencies in the gradle build file. I also tried changing the group name from commons-io to org.apache.commons, and that did not work either.
My project is at a standstill until I get this resolved, and I would appreciate any help I can get.

This is a known and fixed problem in Robospice, caused by an underlying Gradle 2.1 issue: https://github.com/stephanenicolas/robospice/issues/365. The fix is going to be released in the next version.
You can work around it by excluding org.apache.commons:commons-io from all Robospice dependencies, and include commons-io:commons-io:1.3.2 manually. Like this:
// workaround (https://github.com/stephanenicolas/robospice/issues/365)
// remove when robospice updates to 1.4.15+
compile ('com.octo.android.robospice:robospice-retrofit:1.4.14') {
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile ('com.octo.android.robospice:robospice-ormlite:1.4.14') {
exclude group: 'org.apache.commons', module: 'commons-io'
}
compile 'commons-io:commons-io:1.3.2'

I guess this question needs a structured approach towards solving the issue which both of the above answers fail to provide.
Step 1: Find out which external library is causing duplicate zip entry. Run following command from terminal of Android Studio.
gradlew -q dependencies app:dependencies
In my case, image picking library ('net.yazeed44.imagepicker:imagepicker:1.3.0') was causing the duplicate entry.
Step 2: Add code to exclude commons-io only for that library
compile ('net.yazeed44.imagepicker:imagepicker:1.3.0'){
exclude group: 'org.apache.commons', module: 'commons-io'
}
Step 3: Include updated commons-io library.
compile 'commons-io:commons-io:1.3.2'
Now you are set to go.

Related

How to exclude duplicate package from added 3rd party solution [duplicate]

I am not sure what this error means.
Execution failed for task ':excelSior:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class
I am currently using android-support-v4.jar for my libraries
dependencies {
compile project(':addThisSDK')
compile project(':centeredContentButton')
compile project(':googleplayservices_lib')
compile files('libs/adxtag2.4.6.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/aws-android-sdk-1.7.1.1-debug.jar')
compile files('libs/commons-lang-2.6.jar')
compile files('libs/crittercism_v4_4_0_sdkonly.jar')
compile files('libs/dd-plist.jar')
compile files('libs/FiksuAndroidSDK_4.1.1.jar')
compile files('libs/iqengines-sdk-barcode.jar')
compile files('libs/irEventTracker-1.2.jar')
compile files('libs/jolt-core-0.0.7.jar')
compile files('libs/json-utils-0.0.7.jar')
compile files('libs/jsoup-1.7.2.jar')
compile files('libs/kooaba-api-v4-java.jar')
compile 'com.android.support:multidex:1.0.0'
}
Error does not show up during gradle sync. Just when I try to run the application
What could be the problem?
You've probably fixed this by now but just so this doesn't stay unanswered,
Try adding this to your build.gradle:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
You need to check that you have inserted v4 library and compile library? You must not repeat library in your app or your dependence program.
delete the repeat library so that just one V4 remains.
in your app dir build.gradle file
add this command:
android{
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}
it works for me! You can try it!
I also came across this kind issue when re import old eclipse project. It occurred some old dependency as jar file in the project.
just remove
compile fileTree(dir: 'libs', include: '*.jar')
in gradle file
and add dependency in the gradle file.
It works for me ..
In my case the mentioned "duplicate entry" error arised after settingmultiDexEnable=true in the build.gradle.
In order to fully resolve the error first of all have a look at Configure Apps with Over 64K Methods (espescially "Configuring Your App for Multidex with Gradle").
Furthermore search for occurences of the class that causes the "duplicate entry" error using ctrl+n in Android Studio. Determine the module and dependency that contains the duplicate and exclude it from build, e.g.:
compile ('org.roboguice:roboguice:2.0') {
exclude module: 'support-v4'
}
I had to try multiple module labels till it worked. Excluding "support-v4" solves issues related to "java.util.zip.ZipException: duplicate entry: android/support/v4/*"
My understanding is that there are duplicate references to the same API (Likely different version numbers). It should be reasonably easy to debug when building from the command line.
Try ./gradlew yourBuildVariantName --debug from the command line.
The offending item will be the first failure. An example might look like:
14:32:29.171 [INFO] [org.gradle.api.Task] INPUT: /Users/mydir/Documents/androidApp/BaseApp/build/intermediates/exploded-aar/theOffendingAAR/libs/google-play-services.jar
14:32:29.171 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':BaseApp:packageAllyourBuildVariantNameClassesForMultiDex'
14:32:29.172 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :BaseApp:packageAllyourBuildVariantNameClassesForMultiDex FAILED'
In the case above, the aar file that I'd included in my libs directory (theOffendingAAR) included the Google Play Services jar (yes the whole thing. yes I know.) file whilst my BaseApp build file utilised location services:
compile 'com.google.android.gms:play-services-location:6.5.87'
You can safely remove the offending item from your build file(s), clean and rebuild (repeat if necessary).
check your dependencies versions, you must have compatible versions put attention specially to com.google packages, must have same version like:
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'
Both are 8.3.0, if you have another version compilation will throw that exception.
Simple Remove Your Jar file from dependencies gardle.project as v7
and run your project
For Expose.class Error i.e
java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
use the below code
configurations {
all*.exclude module: 'gson'
}
find out the lib depends on the support v4, and exclude it.
code in build.gradle is like this:
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
// http://stackoverflow.com/a/30931887/5210
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
In my situation, the lib 'espresso' has a jar called support-v4 and in my project 'app' have the same support-v4, exclude the support-v4 when import espresso.
PS: it seems compile project can not work with the exclude
This is because you have added a library and given its dependency on a module more than once.
In my case, I had added a library as a module and as a gradle dependency both.
Removing one source of adding library (I removed gradle dependency) solved my problem.
For Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' com.android.build.api.transform.TransformException java.util.zip.ZipException duplicate entry com/google/gson/annotations/Expose.class
Here is what I did:
1) Delete the gson-2.5.jar file.
2) configurations { all*.exclude module: 'gson-2.5' }
I have faced this issue as i have manually copied the jar in libs as well as mentioned the dependency in gradle file. You also check in your project structure, whether the same jar file is copied in any other folder like libs or in project folder.
I had the same problem after upgrading the android SDK. I was able to run the application in the buildToolsVersion '23.0.1', I got the same error when I changed to buildToolsVersion '24.0.3'
I resolved the problem by updating my java version from 1.7 to 1.8 with compileSdkVersion 24
This problem cost me one whole day. I finally downgraded the firebase-ui library version from 2.0.0 to 1.2.0 and added the following code inside Project level build.gradle file:
allprojects {
repositories {
jcenter()
// Add the following code to your project level build.gradle
maven {
url 'https://maven.fabric.io/public'
}
}
}
I also have the issue because of i have compile 'com.android.support:appcompat-v7:24.0.0-alpha1' but i added recyclerview liberary compile 'com.android.support:recyclerview-v7:24.0.2'..i changed the version as same as compat like (24.0.2 intead of 24.0.0).
i got the answer..may be it will help for someone.
In my case the mentioned "duplicate entry" error arised after settingmultiDexEnable=true in the build.gradle.
and exact error which i was getting was below :
Error:Execution failed for task
':android:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
com/google/android/gms/internal/zzqx.class
So first thing I search for class which causes "duplicate entry" error using ctrl+n in Android Studio and searched for com/google/android/gms/internal/zzqx.class and then it was showing 2 entries for gms class with one version 8.4.0 and 1 with version 11.6.0 .
To fix it i made both to use 11.6.0 and it was fixed example
earlier
compile "com.google.android.gms:play-services-games:11.6.0"
compile "com.google.android.gms:play-services-auth:8.4.0"
compile "com.google.android.gms:play-services-ads:11.6.0"
After
compile "com.google.android.gms:play-services-games:11.6.0"
compile "com.google.android.gms:play-services-auth:11.6.0"
compile "com.google.android.gms:play-services-ads:11.6.0"
Rebuilding Fixed .
In my case exact error was below
':android:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqx.class
I was using another version of google apis i.e. in one modules gradle file
if (!project.hasProperty('gms_library_version')) {
ext.gms_library_version = '8.6.0'
}
however in other modules version 11.6.0 as below
compile "com.google.android.gms:play-services-ads:11.6.0"
compile "com.google.android.gms:play-services-games:11.6.0"
compile "com.google.android.gms:play-services-auth:11.6.0"
However to find this i did a ctrl + n in android studio and entered class name zzqx.class and then it displayed 2 jar files being pulled for this class and then i understood that somewhere i am using version 8.6.0 . On changing 8.6.0 to 11.6.0 and rebuilding the project the issue was fixed .
Hope this helps .
More on this here
https://www.versionpb.com/tutorials/step-step-tutorials-libgdx-basic-setup-libgdx/implementing-google-play-services-leaderboards-in-libgdx/
For me something similar happened when I had accidently added
apply plugin: 'kotlin-android'
to my android library module. Removing the line fixes the issue.
I tried all the above solutions but not working for me. I tried update libraries by goto project structure > app. And it works for me! Hope this answer helpful to someone.
Try this:
android {
configurations {
all*.exclude module: 'PhotoView' //去除重复依赖库
}
}

duplicate entry: com/android/volley/AuthFailureError.class while compiling project in android studio

I am using external libraries payu money sdk and linkedin-sdk, both uses volley libraries, which while compiling project gives duplicate entry of AuthFailureError.class
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/android/volley/AuthFailureError.class"
i have also added following code to exclude module, but still same error
configurations{
all*.exclude module: 'com.android.volley'
}
please help
I stumbled upon this same error, and after reading this, I was able to solve it.
Try adding this line inside your app dir build.gradle file -
android{
configurations {
all*.exclude group: 'com.android.volley'
}}
Hope this helps.
I had this problem when I tried to generate the APK (release) and I solved it changing the linkedin-sdk build.gradle:
From:
dependencies {
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:21.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/volley.jar')
androidTestCompile('junit:junit:4.12') }
To:
dependencies {
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:21.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.volley:volley:1.0.0'
androidTestCompile('junit:junit:4.12') }
Add multiDexEnabled true in the defaultConfig section of your gradle file
Then,
compile 'com.android.support:multidex:1.0.1' in your dependencies
Finally add below in your application class:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Also, check if you are using volley.jar in your libs folder. If so, delete that jar file, and compile again. Sometimes, jar dependencies conflicts with those compiled using remote source.
This is an example how to exclude classes in dependencies when there is duplicate entry in gradle.
compile ('com.google.api-client:google-api-client-android:1.17.0-rc') {
exclude module: 'httpclient'
}
or try with your way just add some more text
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
So, now what you have to do is
Search CTRL+SHIFT+N in android studio for the class AuthFailureError.class
See which jar contains this and remove it like above (This is just as an example/You have to figure out the duplicate class and manually remove it)
just remove the duplicate jar file(note:use new version,delete old version) for importing "com.android.volley.AuthFailureError" in build.gradle. Then clean project and rebuild project and then run you will get result.
I had the similar issue while making build on Jenkins, weirdly it was working fine on my local machine. After adding below exclude it worked both on local machine and Jenkins.
android{
configurations {
all*.exclude group: 'com.android.volley'
}}
I have added configurations block to my app's build.gradle inside android section.
If it matter's Compile SDK version is 22 and Build Tools version is 25.0.0
This worked like a charm.
Okay I got my answer
On mac instead of control n, it is command 0 and the command i needed was
configurations {
all*.exclude module: 'volley-release'
}
Just remove your volley library from dependancy.
Try clean and rebuild project it works for me.
Ex. payusdk are also implementing volley library so that is the reason exception shows duplicate entry. I hope it works. because i also found this error and i do these things it works.
Thanks.
Use the below command in Android studio terminal to get the dependency conflict data - [Replace with your app Name]
./gradlew -q :<app>:dependencyInsight --dependency volley --configuration compile
If you are using latest Volley library from android [https://github.com/google/volley/releases], add below two lines in your build.gradle file under each of the compile library entries that has conflict.
Ex:
compile('com.xyz:abc:1.1.0-RELEASE') {
exclude module: 'library'
exclude group: 'com.mcxiaoke.volley'
}

In an Android Gradle build, how to exclude dependencies from an included jar file?

In my Android project, I use a library that comes as a jar.
I include it in the dependencies section like so:
dependencies {
...
compile files('libs/thethirdpartylibrary.jar')
...
}
I also want to use the okhttp library, which I include like this:
compile ('com.squareup.okhttp:okhttp:2.7.5')
(This particular version of okhttp depends on okio 1.6.0.)
The problem is that the thirdparty jar library depends on okio v0.9.0 and what's worse, bundles it.
As a result, I get a dex conflict error at build time.
I was able to resolve this by manually removing okio from the jar file and this seems to work. But I'm wondering if there's a way to do this in gradle.
My question: Can I remove bundled, transitive ( <- I hope I'm using this word the right way) dependencies from an included jar during build-time with gradle?
Exclude the Group in the dependencies by using the below lines.
1.
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
2.
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile ("com.xxx:xxx-commons:1.+") {
exclude group: 'junit', module: 'junit'
}
}
3.
configurations {
runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}
Try this one.
For more detail
According to this discussion here https://groups.google.com/forum/#!topic/adt-dev/g1AiJM7PeVs, what you want to do is not possible.
The syntax suggested in the other answers is for "normal" Maven dependencies.

gradle dependency error in android

In the following build.gradle, I added the configuration section to avoid double inclusion of support libraries. Support libraries are used in the main project and in the dependent projects like facebook sdk. Without the configuration section, I get "UNEXPECTED TOP-LEVEL EXCEPTION". Adding that configuration makes the error go away and the app all works fine.
Now, I'm trying to add RecyclerView to my app and I get RecyclerView class not found while inflating the recyclerview (although it builds ok). If I remove the facebook SDK and configuration section, the recyclerview works just fine.
Question: What changes can I make to the build.gradle to make the facebook SDK work and RecyclerView work? In other words, why is the config section excluding v7 when it is only supposed to exclude v4?
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-v13:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.google.android.gms:play-services:4.4.52'
compile project(':facebook-3.15')
compile project(':parse-1.5.1')
compile project(':viewpagerindicator-2.4.1')
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
If you're having a dependency conflict with the v4 support library, you can just exclude it from one of the libraries via the gradle script:
compile ('com.android.support:recyclerview-v7:+') {
exclude module: 'support-v4'
}
I fixed that adding:
compile ('com.facebook.android:facebook-android-sdk:3.22.0#aar'){
exclude module: 'support-v4'
}
Found a solution to this:
Removed the config section in the build.gradle that excludes support-v4
It turns out that .aar files are basically a zip, so removed the support-v4 jar from the dependency .aar library (using 7-zip).
And now, I don't get the top-level exception and at the same time able to use recyclerview-v7.
If you are using dependency projects instead of .aar files, try removing the support-v4.jar files in the dependency projects before compiling.
Shouldn't the gradle build tool be intelligent enough to exclude the duplicate packages rather than having the users go thru this kind of workarounds and headaches?

Duplicate files while including butterknife with gradle

I have a basic Android app that I created with Android Studio, and I'm having problems adding butterknife to my build. I get this error:
Error:: duplicate files during packaging of APK C:\apps\orion\app\build\apk\app-debug-unaligned.apk
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/services/javax.annotation.processing.Processor
File 1: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
File 2: C:\Users\andres\.gradle\caches\modules-2\files-2.1\com.jakewharton\butterknife\4.0.1\f43b36925363701633d01adb8e54df7150397a78\butterknife-4.0.1.jar
My dependencies look like this:
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.jakewharton:butterknife:4.0.1'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:+'
compile project(':lib')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Later versions of the plugin will tell you how to fix this. I think we introduced the fix in 0.8 so you should probably upgrade. Then the fix is to put this in your build.gradle
android {
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
This will exclude this file from the packaging which is fine since it's not actually needed in the APK.
That's because you wrote compile for dagger-compiler, replace it with provided and the issue will be fixed.
compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
The best option in version >= 0.9.1 of Gradle build tools is probably:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.annotation.processing.Processor'
}
}
For more, see the Android Tools Project page: New Build System.
Edit:
One last note here if you start having problems with generated code, make sure to structure your dependencies properly. I ended up removing any exclusion of the Processor line and structuring my annotation processed dependencies like:
compile "org.parceler:parceler-api:0.2.15"
apt "org.parceler:parceler:0.2.15"
and
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
If after applying above given solutions you still face the same issue as I was, then if you are using glide library then change the version of the glide to it's max.
eg.
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

Categories

Resources