我在将 Twitter Fabric SDK 集成到我的应用程序时遇到了困难。我按照Twitter 教程的步骤进行操作,一切顺利,但是当我尝试使用 gradle 构建项目时,出现以下错误:
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)
我尝试从我的应用程序模块 lib 文件夹中删除我的静态 Gson 库,之后一切正常。从 gradle 模块依赖项中删除添加 twitter sdk 的行时也是如此,所以我很确定这两者之间存在某种冲突,我正在寻求解决它。
任何帮助将不胜感激 !
如果它对那里的人有任何用处,那就是我的 gradle 应用程序模块文件:
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;
}
}