Marcel
Marcel

Reputation: 2194

Twitter4j + support v7 dependency problems with Android Studio

I'm trying to run my app after integrate the twitter4j jar dependency and I'm getting troubles with it.

This is my gradle file:

dependencies {
    compile 'com.squareup.retrofit:retrofit:1.5.1'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.nhaarman.listviewanimations:library:2.6.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'ch.acra:acra:4.5.0'
    compile 'de.psdev.licensesdialog:licensesdialog:1.4.0'
    compile (group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.1') {
        exclude group: 'com.google.android', module: 'support-v7'
    }
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

As you can see I'm importing the twitter4j but I'm getting troubles with the depencies.

This is the output of the gradle console, after this line:

C:...path...\build\intermediates\pre-dexed\debug\twitter4j-core-4.0.1-cba1ebcdb3cdaa1deeed0e45ec882496572212ad.jar

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
        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)

I try to exclude the support lib, I try importing the jar dircetly into the libs folder, but I'm always getting this problem.

Anyone has face with this issue or any idea how can I solve it?

Thank you.

Upvotes: 0

Views: 791

Answers (1)

Scott Barta
Scott Barta

Reputation: 80020

I added an exclude for the support-v4 library to each of your dependencies in turn until I found the offending one. It seems to be mispackaged. Change this line:

compile 'de.psdev.licensesdialog:licensesdialog:1.4.0'

to this:

compile ('de.psdev.licensesdialog:licensesdialog:1.4.0') {
    exclude group: 'com.google.android', module: 'support-v4'
}

Upvotes: 1

Related Questions