I'm having difficulties integrating Twitter Fabric SDK to my app. I followed the steps of the Twitter tutorial and everyhting went fine but when I try to build my project with gradle, I get this error :
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\Android\android-studio\sdk\build-tools\android-4.4W\dx.bat --dex --output ...
Error Code: 2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer;
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 tried removing my static Gson library from my app module lib folder and everything went fine afterwards. Same when removing the line adding twitter sdk from the gradle module dependencies so I'm pretty sure there is some kind of conflict between these two and I'm looking to resolve it.
Any help would be greatly appreciated !
In case it could be of any use to people out there here is my gradle app module file :
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
...
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
ext.enableCrashlytics = false
}
}
}
repositories {
jcenter()
mavenCentral()
maven{ url 'https://maven.fabric.io/repo'}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':facebook')
compile 'com.android.support:support-v13:20.0.0'
compile 'com.google.android.gms:play-services:6.1.11'
compile('com.twitter.sdk.android:twitter:1.0.0@aar') {
transitive = true;
}
}
I'm a Twitter Android developer.
Try running ./gradlew app:dependencies
to see all the dependencies of your gradle tasks. Your compile dependencies will include something like:
+--- com.twitter.sdk.android:twitter-core:1.0.0
| | +--- com.squareup.retrofit:retrofit:1.6.1
| | | \--- com.google.code.gson:gson:2.2.4
| | +--- com.google.code.gson:gson:2.2.4
| | \--- io.fabric.sdk.android:fabric:1.0.0
which shows that GSON is indeed used by Fabric internally.
My recommendation would be to remove GSON from your libs/ folder and add it as a direct dependency in your build.gradle instead of excluding it from the Twitter deps graph. You may as well take advantage of the dependency resolution mechanisms in the build tool.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) // Maybe remove this.
compile project(':facebook')
compile 'com.android.support:support-v13:20.0.0'
compile 'com.google.android.gms:play-services:6.1.11'
compile('com.twitter.sdk.android:twitter:1.0.0@aar') {
transitive = true;
}
compile 'com.google.code.gson:gson:2.2.4' // Added.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With