0

I have 3 modules that im building.

A (an android library with no dependencies) B (an android library with dependency on A) C (an android application with dependency on B and A)

first, i want to declare in C only about B and have A transitively second, i keep getting dex error:

Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/collections/Buffer;
Unknown source file :   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file :   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file :   at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file :   at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file :   at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file :   at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file :   at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file :   at com.android.dx.command.Main.main(Main.java:106)

:app:dexDebug FAILED

i provide the dependencies declared in modules B,C (A does not have any)

B:

dependencies {
    compile 'com.me.project:project-base:1.0.0'
    compile 'org.apache.httpcomponents:httpcore:4.3'
    compile 'org.apache.httpcomponents:httpmime:4.3'
    compile 'commons-io:commons-io:2.4'
}

C:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:gridlayout-v7:23.1.0'
    compile ('B')
    compile 'com.android.support:support-v4:23.1.0'
    compile 'commons-validator:commons-validator:1.4.1'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'

    // TODO: check how to make it transitive somehow
    compile 'com.me.project:project-base:1.0.0'

    // only simbols to compile time
    provided 'org.apache.httpcomponents:httpcore:4.3'
    provided 'org.apache.httpcomponents:httpmime:4.3'
    provided 'commons-io:commons-io:2.4'
}

please help me in how to configure the project correctly and solve me error

thanks!!

Gur
  • 111
  • 8

2 Answers2

0

As the exception message suggests, the commons-collections dependency is being added twice.

From a quick look, I see that commons-validator library depends on commons-collections. You have to find if commons-collections is transitively added by another dependency.

Tools that can help you with that are:

Print all the compile dependencies (from root of your project, where app is name of your application module):
./gradlew app:dependencies --configuration compile

Use dependency insight report:
./gradlew app:dependencyInsight --configuration compile --dependency commons-collections

If the above options were not effective, then it is possible that commons-collections classes are packaged in a fat-jar. Print all your compile dependencies with the below task and check whether one of the jars includes commons-collections classes (run it with ./gradlew app:printDependencies):

task printDependencies << {
    configurations.compile.each { println it.name }
}

As a side note, commons-validator v1.4.1 depends on a vulnerable commons-collections 3.2.1 version. Make sure you're using commons-collections 3.2.2 or above.

Alex Lipov
  • 13,503
  • 5
  • 64
  • 87
0

First of all, thanks everybody for your effort.

I got this error cause i had the same symbol twice. It came from two different dependencies.

I ran gradle dependencies to get the dependecies tree to find those jars.

after that i added 'exludes' to one of them in my build.gradle file under dependencies.

that solved my problem cause now the dex process have each symbol only once.

Again, thanks everybody. Youve been very helpful

Gur
  • 111
  • 8