Alexander Kohler
Alexander Kohler

Reputation: 1967

Trouble with building android project with Gradle (Multiple dex files)

Since the release of 1.0, I'm finally moving over to AS.. I don't have too much experience with Gradle, so bear with me. I've found a couple of answers that seem to be putting me on the right track, however, I've yet to find a generic answer that will help me. (Most of the answers are just "replace your jar with this.."). It seems as though I have a dependency linked twice somewhere, however, I'm not quite sure where...

Here is the error I am getting

Output:

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/view/PagerAdapter; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103)

And here are my dependencies on my main project:

dependencies { compile project(':swipeBackLibrary') compile 'com.android.support:appcompat-v7:19.1.0' compile files('libs/android-support-v13.jar') compile files('libs/libGoogleAnalyticsServices.jar') }

I'm guessing I have a collision somewhere. How can I check where PagerAdapter is getting its source(s)? Thanks guys.

Upvotes: 0

Views: 208

Answers (1)

Scott Barta
Scott Barta

Reputation: 80010

The appcompat library includes the support library, which is where the duplication comes from. Since you've included the support library as a jarfile instead of referring to it via Maven coordinates, the build system can't disambiguate the multiple copies of the library and prevent the error. You can fix it by moving to a coordinate-based spec for the support library:

dependencies {
    compile project(':swipeBackLibrary')
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.android.support:support-v13:19.1.0'
    compile files('libs/libGoogleAnalyticsServices.jar')
}

Upvotes: 3

Related Questions