我知道这个问题已经被提出但我找不到合适的答案来解决我的问题。我希望你们能帮助我。
该异常告诉Multiple dex files defined
我尝试了几种解决此问题的常用方法。不幸的是,这没有任何帮助。
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Cause: com.android.dex.DexException: Multiple dex files define Lnet/jcip/annotations/GuardedBy;
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lnet/jcip/annotations/GuardedBy;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
我尝试清理并重建项目。
然后我尝试使缓存无效并重新启动。
我也运行此命令来了解依赖项中的重复项:
./ gradlew -q dependencies app:dependencies --configuration compile --stacktrace
这是输出。如您所见,没有重复。
+--- com.jakewharton.hugo:hugo-annotations:1.2.1
+--- com.google.code.findbugs:annotations:3.0.1
| +--- net.jcip:jcip-annotations:1.0
| \--- com.google.code.findbugs:jsr305:3.0.1
+--- com.michaelpardo:activeandroid:3.1.0-SNAPSHOT
+--- com.android.support:appcompat-v7:23.1.1
+--- com.crashlytics.sdk.android:crashlytics:2.3.0
| +--- com.crashlytics.sdk.android:crashlytics-core:2.3.0
| | \--- io.fabric.sdk.android:fabric:1.3.1
| +--- io.fabric.sdk.android:fabric:1.3.1
| \--- com.crashlytics.sdk.android:beta:1.1.2
| \--- io.fabric.sdk.android:fabric:1.2.0 -> 1.3.1
+--- com.greenhalolabs:emailautocompletetextview:1.3.0
+--- com.facebook.android:facebook-android-sdk:4.2.0
| \--- com.parse.bolts:bolts-android:1.2.0
+--- com.android.support:cardview-v7:23.1.1
+--- com.jakewharton.hugo:hugo-runtime:1.2.0
| +--- com.jakewharton.hugo:hugo-annotations:1.2.0 -> 1.2.1
| \--- org.aspectj:aspectjrt:1.8.5
+--- joda-time:joda-time:2.0
+--- io.keen:keen-client-api-android:2.1.2
+--- com.googlecode.libphonenumber:libphonenumber:6.3.1
+--- net.simonvt.menudrawer:menudrawer:3.0.6
+--- com.squareup:otto:1.3.0
+--- com.google.android.gms:play-services-base:8.4.0
| \--- com.google.android.gms:play-services-basement:8.4.0
+--- com.google.android.gms:play-services-analytics:8.4.0
+--- com.google.android.gms:play-services-gcm:8.4.0
| \--- com.google.android.gms:play-services-measurement:8.4.0
+--- com.jeremyfeinstein.slidingmenu:library:1.3
+--- com.android.support:support-v4:23.1.1
| \--- com.android.support:support-annotations:23.1.1
+--- com.jakewharton.timber:timber:3.1.0
+--- com.viewpagerindicator:library:2.4.1
+--- com.ouralabs:ouralabs:2.7.0
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.1
+--- project :domain
| \--- joda-time:joda-time:2.0
\--- project :remote
+--- com.squareup.retrofit:retrofit:1.6.0
| \--- com.google.code.gson:gson:2.2.4
+--- com.squareup.okhttp:okhttp:2.4.0
| \--- com.squareup.okio:okio:1.4.0
\--- com.squareup.okhttp:okhttp-urlconnection:2.4.0
multiDexEnabled true
,但我确信我没有超出方法限制。此问题立即出现,无需添加任何库。我甚至无法组装旧代码的生产版本。它们正在生产中并且完全可以编译。 模块的build.gradle:
dependencies {
apply plugin: 'idea'
compile "com.michaelpardo:activeandroid:${rootProject.ext.activeandroid}"
compile(group: 'com.google.code.findbugs', name: 'annotations', version: "${rootProject.ext.findbugs}") {
exclude(group: 'net.jcip', module: 'jcip-annotations')
}
compile(group: 'com.android.support', name: 'appcompat-v7', version: "${rootProject.ext.supportv4}") {
exclude(group: 'com.android.support', module: 'support-v4')
}
compile(group: 'com.crashlytics.sdk.android', name: 'crashlytics', version: "${rootProject.ext.crashlytics}") {
exclude(group: 'com.crashlytics.sdk.android', module: 'answers')
}
compile "com.greenhalolabs:emailautocompletetextview:${rootProject.ext.emailautocomplete}"
compile(group: 'com.facebook.android', name: 'facebook-android-sdk', version: "${rootProject.ext.facebook}") {
exclude(group: 'com.android.support', module: 'support-v4')
}
compile "com.android.support:cardview-v7:${rootProject.ext.supportv4}"
compile "com.jakewharton.hugo:hugo-runtime:${rootProject.ext.hugo}"
compile "joda-time:joda-time:${rootProject.ext.jodatime}"
compile "io.keen:keen-client-api-android:${rootProject.ext.keen}"
compile "com.googlecode.libphonenumber:libphonenumber:${rootProject.ext.libphonenumber}"
compile "net.simonvt.menudrawer:menudrawer:${rootProject.ext.menudrawer}"
compile "com.squareup:otto:${rootProject.ext.otto}"
compile(group: 'com.google.android.gms', name: 'play-services-base', version: "${rootProject.ext.playservices}") {
exclude(group: 'com.android.support', module: 'support-v4')
}
compile(group: 'com.google.android.gms', name: 'play-services-analytics', version: "${rootProject.ext.playservices}") {
exclude(group: 'com.google.android.gms', module: 'play-services-basement')
}
compile(group: 'com.google.android.gms', name: 'play-services-gcm', version: "${rootProject.ext.playservices}") {
exclude(group: 'com.google.android.gms', module: 'play-services-base')
exclude(group: 'com.google.android.gms', module: 'play-services-basement')
}
compile "com.jeremyfeinstein.slidingmenu:library:${rootProject.ext.slidingmenu}"
compile "com.android.support:support-v4:${rootProject.ext.supportv4}"
compile "com.jakewharton.timber:timber:${rootProject.ext.timber}"
compile "com.viewpagerindicator:library:${rootProject.ext.viewpagerindicator}"
compile "com.ouralabs:ouralabs:${rootProject.ext.ouralabs}"
compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"
compile project(':domain')
compile(project(':remote')) {
exclude module: 'domain'
}
// Local Unit testing
testCompile "junit:junit:$rootProject.ext.junit"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
// Instrumentation Testing
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.uiautomator:uiautomator-v18:$rootProject.ext.uiautomator"
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"
androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion"
androidTestCompile "com.google.dexmaker:dexmaker:$rootProject.ext.dexmaker"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:$rootProject.ext.dexmaker"
}
更新
我检查了项目GuardedBy
。它看起来像重复吗?
答案 0 :(得分:1)
看起来hugo-annotations
包含两次。它是hugo-runtime
的依赖关系,并从其他地方添加。尝试将其从hugo-runtime
compile("com.jakewharton.hugo:hugo-runtime:${rootProject.ext.hugo}") {
exclude(group: 'com.jakewharton.hugo' module: 'hugo-annotations')
}
此外,由于错误是由于jsr库可能需要将其从findbugs
依赖项中排除。
compile(group: 'com.google.code.findbugs', name: 'annotations', version: "${rootProject.ext.findbugs}") {
exclude(group: 'net.jcip', module: 'jcip-annotations')
exclude(group: 'com.google.code.findbugs', module: 'jsr305')
}
编辑:
如果你真的找不到它,那就有一个核选项,但我不确定它是否会破坏别的东西或者是最好的做法。这将完全从类路径中删除jsr305
。
dependencies {
...
}
configurations.all*.exclude module: 'jsr305'
答案 1 :(得分:0)
检查您的jar文件。您可以在项目资源管理器中展开文件。 如果它有不必要的路径和BuildConfig,则应该发生DexException。