As the title says, Multiple dex files are being defined, I'ven been digging around with no luck on how to solve this one, so I decided to reach out on the community, to make the story short, I'm updating the gradle build system of this legacy project from gradle 0+ to gradle 3+, I managed to refactor the common configurations such as flavoring, dependencies (from compile to api/implementation), (you name it..), until I stumbled on this dex issue, the first thing that came to my mind is to break down the dependencies by the help of Using gradle to find dependency tree, but unfortunately its taking my time too much on gradlew commands and still ending up with gradlew issues(unable to execute AndroidSdk something), so I took a step back(to minimize the time I needed) and did this... (playing the odds)
dependencies {
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.google.code.gson:gson:2.3'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.picasso:picasso:2.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.okhttp:okhttp:2.4.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('org.bitbucket.b_c:jose4j:0.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'commons-io',name:'commons-io',version: '2.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'com.jcraft', name: 'jsch', version: '0.1.44-1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.facebook.android:facebook-android-sdk:4.10.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.github.PhilJay:MPAndroidChart:v3.0.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-compress', version: '1.3') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-vfs2', version: '2.2') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.commons', module: 'logging'
}
api fileTree(dir: 'libs', include: ['*.jar'])
api files('libs/nfc7003.jar')
api files('libs/minilcd7003.jar')
api files('libs/Scan7003.jar')
api files('libs/UserInterface.jar')
api files('libs/printer7003.jar')
}
I cant figure out whos dependency in the above list has this transitive issue with the logging framework, I define an exclusion on them all, still no luck..
just to mention the reason behind : I need the advance profiling of Android studio 3, and the latest gradle(4+)/build tool(3+) must be used to be able to do so, that lead me here ..
please help me on this one, thanks in advance...
[Edit] Build message:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error:com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error: at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at
com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at
com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at
com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.
ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at
java.util.concurrent.
ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at
java.util.concurrent.
ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task '
:<omitted project name>:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException:
com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
The problem is because you are using duplicated library in your build.gradle.
First, for support library, you need to use the same version. Do not use the following:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
instead use the following:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:25.4.0'
// appcompat is implicitly include within support design.
Second, for google play service, use the same version. Do not use the following:
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
instead use:
// Dont use the whole play service library
//implementation 'com.google.android.gms:play-services:9.8.0'
implementation 'com.google.android.gms:play-services-gcm:9.8.0'
implementation 'com.google.android.gms:play-services-auth:9.8.0'
Third, to exclude common-logging you need to use something like this:
compile(group: 'org.apache.commons', name: 'commons-compress', version: '1.3'){
exclude group: 'commons-logging', module: 'commons-logging'
}
or use the following:
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}
You don't need to adding exclude to every library because some library didn't have any commons-logging inside them.
try
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
remove all exclude options and commons-io.
above dependency might just work fine
when I try to run the app I am getting this error
before
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzsk.class
Now
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqz$zza.class
I referred this,this and this. Tried the solutions mentioned there. Still I am far away from solving the Issue.
Please have a look on the app build gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.android.support:appcompat-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:recyclerview-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:cardview-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:design:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.clevertap.android:clevertap-android-sdk:2.0.11'
compile 'com.android.support:support-v4:23.1.1'
compile('com.google.android.gms:play-services-analytics:8.3.0')
{
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile "com.squareup.picasso:picasso:2.4.0"
compile('com.google.android.gms:play-services-gcm:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile('com.google.android.gms:play-services:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile 'de.hdodenhof:circleimageview:1.3.0'
compile project(':volley')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.android.support:multidex:'
apply plugin: 'com.google.gms.google-services'
}
I am happy to provide more information if needed.
UPDATE
When I comment compile 'com.clevertap.android:clevertap-android-sdk:2.0.11' It is working fine.
please check if some of your dependencies have multidex as dependency and exclude it. For example for Facebook SDK: you have this
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
change to this
compile('com.facebook.android:facebook-android-sdk:4.7.0') {
exclude group: 'com.android.support', module: 'multidex'
}
and check for other also.
Solved the issue by updating the com.google.android.gms:play-services version
from 8.3.0 to 8.4.0
I am facing, Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: android/support/annotation/AttrRes.class
build.gradle file (main project)
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-location:7.8.0'
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile 'com.google.android.gms:play-services-nearby:7.8.0'
compile ('com.android.support:recyclerview-v7:+') {
exclude module: 'support-v4'
}
compile 'com.firebase:firebase-client-android:2.3.1+'
compile ('com.android.support:cardview-v7:22.0.+') {
exclude module: 'support-v4'
}
compile ('com.squareup.okhttp:okhttp:2.4.0') {
exclude module: 'support-v4'
}
compile ('com.squareup.picasso:picasso:2.5.2') {
exclude module: 'support-v4'
}
compile ('com.squareup.retrofit:retrofit:2.0.0-beta1') {
exclude module: 'support-v4'
}
compile('com.squareup.retrofit:converter-gson:2.0.0-beta1') {
exclude module: 'gson'
}
compile('com.segment.analytics.android:all:2.5.1#aar') {
transitive = true
exclude module: 'support-v4'
}
compile ('com.android.support:design:22.2.0') {
exclude module: 'support-v4'
}
compile('com.uservoice:uservoice-android-sdk:1.2.+') {
exclude module: 'commons-logging'
exclude module: 'httpcore'
exclude module: 'httpclient'
}
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
compile project(':contactsChipView')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile project(':facebook-android-sdk-4.0.1')
compile ('com.android.support:multidex:1.0.0'){
exclude module: 'support-v4'
}
Files in /libs directory (main project):
gson-2.2.3.jar
Parse-1.9.2.jar
YoutubeAnddroidPlayerApi.jar
Files in /libs directory (facebook module):
android-support-v4.jar
bolts.jar
As you can see the above gradle file, I have tried adding exclude for almost all dependencies. But still, no luck.
I also tried changing build tools from 22.0.1 to 22.0.0, even this didn't work.
I went through other posts, but no luck.
Anybody knows how to solve this?
I'm using android studio. I'm developing an app with google cloud appengine (endpoints) and google cloud storage. When I write the gradle dependencies as shown:
dependencies {
compile 'com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:multidex:1.0.1'
compile project(path: ':backend', configuration: 'android-endpoints')
compile files('libs/joda-time-2.8.2.jar')
compile ('com.google.appengine.tools:appengine-gcs-client:0.4.4')
compile files('libs/guava-18.0.jar')
}
I retrieve an error when compiling:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/google/common/reflect/TypeToken$TypeCollector$ForwardingTypeCollector.class
I've tried to exclue in this way
compile ('com.google.appengine.tools:appengine-gcs-client:0.4.4'){
exclude group: 'com.google.guava'
}
But nothing works. Can anybody help me?
1) First of all let's remove this ugly jars from your dependencies. I am about joda-time and guava
compile 'joda-time:joda-time:2.8.2'
compile 'com.google.guava:guava:18.0'
2) Move exclude group: 'com.google.guava' from appengine to apis
compile ('com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0') {
exclude group: 'com.google.guava'
}
And add it to your :backend
compile (project(path: ':backend', configuration: 'android-endpoints')) {
exclude group: 'com.google.guava'
}
3) Now you can get this error com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '...java'' finished with non-zero exit value 1
If yes we should add exclude to appengine
compile('com.google.appengine.tools:appengine-gcs-client:0.4.4') {
exclude group: 'javax.transaction'
}
4) Now you get Duplicate files copied in APK META-INF/NOTICE.txt
And this we solve with packagingOptions in android {} section
packagingOptions {
exclude 'META-INF/NOTICE.txt'
}
So your final result
android {
...
packagingOptions {
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile (project(path: ':backend', configuration: 'android-endpoints')) {
exclude group: 'com.google.guava'
}
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:multidex:1.0.1'
compile 'joda-time:joda-time:2.8.2'
compile 'com.google.guava:guava:18.0'
compile ('com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0') {
exclude group: 'com.google.guava'
}
compile('com.google.appengine.tools:appengine-gcs-client:0.4.4') {
exclude group: 'javax.transaction'
}
}
I am running to an issue when i run my gradle build. It seems like there are duplicate dependencies getting imported but finding it hard to debug, any suggestions would be great.
Error:Execution failed for task ':proguardDebug'.
java.io.IOException: Can't write [.......\build\intermediates\classes-proguard\debug\classes.jar] (Can't read [.......gradle\caches\modules-2\files-2.1\org.roboguice\roboguice\3.0.1\24e814f35d5cc28eaa7e9f07a50ea69deeb2b544\roboguice-3.0.1.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [roboguice-3.0.1.jar:javax/inject/Inject.class]))
dependencies {
repositories {
mavenCentral()
}
compile 'com.google.android:multidex:0.1'
compile files('libs/aws-android-sdk-1.7.1.1.jar')
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'com.google.android.gms:play-services:+'
compile 'com.androidmapsextensions:android-maps-extensions:2.1.+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:20.+'
compile 'com.jeremyfeinstein.slidingmenu:library:1.3#aar'
compile('com.commonsware.cwac:camera-v9:0.6.+') {
exclude module: 'support-v4'
}
compile 'com.squareup:otto:1.3.6'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okio:okio:1.2.0'
compile project(':libraries:facebook')
compile files('libs/Catalano.Core.jar')
compile files('libs/Catalano.Android.Image.jar')
compile files('libs/Catalano.Math.jar')
compile 'org.roboguice:roboguice:3.+'
provided 'org.roboguice:roboblender:3.+'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.android.support.test.espresso:espresso-core:2.0'
compile 'com.android.support.test:testing-support-lib:0.1'
compile 'com.android.support.test.espresso:espresso-contrib:2.0'
compile 'junit:junit:4.12'
compile 'org.hamcrest:hamcrest-core:1.1'
compile 'org.hamcrest:hamcrest-library:1.1'
compile 'org.hamcrest:hamcrest-integration:1.1'
compile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
You can figure out what is pulling in dependencies by running this command in your project root:
./gradlew app:androidDependencies
You will get output similar to this:
Also, don't forget to check your app/libs/ folder to ensure it's empty if you're pulling everything in with Gradle.