2

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;
mr.boo
  • 73
  • 6

2 Answers2

0

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

Dhaval Patel
  • 300
  • 1
  • 11
  • Thank you for the response, I tried it hours ago(without all the exclusions yet, removed the commons.io dependency), still no luck, but let me try it again after all the changes and attempts I made, lets see if there will be any progress.. – mr.boo Mar 07 '18 at 05:25
0

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.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • Thank you so much for the detailed response, just 1 question before I apply the changes, where should I put the configurations method? is it inside the android { .. } ? or outside of it? – mr.boo Mar 07 '18 at 06:09
  • Thanks so much, it solved the multi dex issue, just have to deal with the conflicts and clean some stuffs(its gonna be nightmare now), thanks anyway :) – mr.boo Mar 07 '18 at 06:26
  • Glad it helps you. I hope you sleep well ;) – ישו אוהב אותך Mar 07 '18 at 06:34