我正在尝试将Espresso 2添加到我的项目中(该项目还具有许多其他依赖项),但是在尝试运行测试时遇到了此错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/test/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
...
非测试版本工作正常。
有人有调试最佳方法的任何技巧吗?
我尝试运行./gradlew -q :<my_project>:dependencies
,但是看不到任何明显的问题(尽管我对解释其输出了解不多):
<snip>
androidTestCompile - Classpath for compiling the androidTest sources.
+--- com.squareup.spoon:spoon-client:1.1.2
+--- com.google.dexmaker:dexmaker-mockito:1.0
| +--- com.google.dexmaker:dexmaker:1.0
| \--- org.mockito:mockito-core:1.9.5
| +--- org.hamcrest:hamcrest-core:1.1
| \--- org.objenesis:objenesis:1.0
+--- com.google.dexmaker:dexmaker:1.0
+--- org.mockito:mockito-core:1.9.5 (*)
+--- com.jayway.android.robotium:robotium-solo:5.3.1
+--- com.android.support.test.espresso:espresso-core:2.0
| +--- com.squareup:javawriter:2.1.1
| +--- org.hamcrest:hamcrest-integration:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- org.hamcrest:hamcrest-library:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- javax.inject:javax.inject:1
| +--- com.android.support.test.espresso:espresso-idling-resource:2.0
| +--- com.android.support.test:testing-support-lib:0.1
| | \--- junit:junit-dep:4.10
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- com.google.code.findbugs:jsr305:2.0.1
| +--- javax.annotation:javax.annotation-api:1.2
| \--- org.hamcrest:hamcrest-core:1.1
\--- com.android.support.test:runner:0.2
+--- junit:junit-dep:4.10 (*)
+--- com.android.support.test:exposed-instrumentation-api-publish:0.2
\--- com.android.support:support-annotations:22.0.0
<snip>
compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:22.1.0
| \--- com.android.support:support-v4:22.1.0
| \--- com.android.support:support-annotations:22.1.0
+--- com.android.support:support-v4:22.1.0 (*)
+--- com.afollestad:material-dialogs:0.7.2.4
| +--- com.android.support:support-v4:22.0.0 -> 22.1.0 (*)
| +--- com.android.support:appcompat-v7:22.0.0 -> 22.1.0 (*)
| +--- com.android.support:support-annotations:22.0.0 -> 22.1.0
| \--- com.android.support:recyclerview-v7:22.0.0
| +--- com.android.support:support-v4:22.0.0 -> 22.1.0 (*)
| \--- com.android.support:support-annotations:22.0.0 -> 22.1.0
+--- com.google.android.gms:play-services-base:7.0.0
| \--- com.android.support:support-v4:22.0.0 -> 22.1.0 (*)
+--- com.google.android.gms:play-services-gcm:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- de.greenrobot:greendao:1.3.7
+--- de.greenrobot:eventbus:2.2.0
+--- com.squareup.wire:wire-runtime:1.4.0
| \--- com.squareup.okio:okio:0.6.0 -> 1.0.1
+--- com.squareup.okio:okio:1.0.1
+--- com.squareup.okhttp:okhttp-urlconnection:2.0.0
| \--- com.squareup.okhttp:okhttp:2.0.0
| \--- com.squareup.okio:okio:1.0.0 -> 1.0.1
+--- com.squareup.retrofit:retrofit:1.6.0
| \--- com.google.code.gson:gson:2.2.4
+--- com.squareup.retrofit:converter-wire:1.6.0
| +--- com.squareup.retrofit:retrofit:1.6.0 (*)
| \--- com.squareup.wire:wire-runtime:1.2.0 -> 1.4.0 (*)
+--- com.squareup.okhttp:okhttp:2.0.0 (*)
+--- com.squareup.picasso:picasso:2.4.0
+--- com.path:android-priority-jobqueue:1.1.2
| \--- com.google.android:android:2.2.1
| +--- commons-logging:commons-logging:1.1.1
| +--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| +--- org.khronos:opengl-api:gl1.1-android-2.1_r1
| +--- xerces:xmlParserAPIs:2.6.2
| +--- xpp3:xpp3:1.1.4c
| \--- org.json:json:20080701
+--- com.netflix.rxjava:rxjava-android:0.16.1
| \--- com.netflix.rxjava:rxjava-core:0.16.1
+--- com.nineoldandroids:library:2.4.0
+--- it.sephiroth.android.library.horizontallistview:hlistview:1.2.2
| \--- com.android.support:support-v4:19.1.+ -> 22.1.0 (*)
+--- com.joooonho:selectableroundedimageview:1.0.1
+--- com.crashlytics.sdk.android:crashlytics:2.0.1
| +--- com.crashlytics.sdk.android:answers:1.0.1
| | \--- io.fabric.sdk.android:fabric:1.0.1
| +--- io.fabric.sdk.android:fabric:1.0.1
| \--- com.crashlytics.sdk.android:beta:1.0.1
| \--- io.fabric.sdk.android:fabric:1.0.1
+--- com.mixpanel.android:mixpanel-android:4.5.3
\--- com.facebook.android:facebook-android-sdk:4.0.0
+--- com.android.support:support-v4:[21,22) -> 22.1.0 (*)
\--- com.parse.bolts:bolts-android:1.1.4
<snip>
我也尝试搜索build/intermediates
目录的子文件夹,但看不到任何冒烟者(尽管我不确定我是否以正确的方式搜索了所有外部依赖项JAR)。
这是我的build.gradle的依赖项部分:
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-v4:22.1.0'
compile 'com.afollestad:material-dialogs:0.7.2.4'
compile 'com.google.android.gms:play-services-base:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0'
compile 'de.greenrobot:greendao:1.3.7'
compile 'de.greenrobot:eventbus:2.2.0'
compile 'com.squareup.wire:wire-runtime:1.4.0'
compile 'com.squareup.okio:okio:1.0.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.retrofit:retrofit:1.6.0'
compile 'com.squareup.retrofit:converter-wire:1.6.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.path:android-priority-jobqueue:1.1.2'
compile 'com.netflix.rxjava:rxjava-android:0.16.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'it.sephiroth.android.library.horizontallistview:hlistview:1.2.2'
compile 'com.joooonho:selectableroundedimageview:1.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.0.1@aar') {
transitive = true;
}
compile "com.mixpanel.android:mixpanel-android:4.5.3"
compile "com.facebook.android:facebook-android-sdk:4.0.0"
// For the Rollbar JAR, as it is not available in Maven central
compile fileTree(dir: 'libs', include: '*.jar')
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.3.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:runner:0.2'
}
更新:
当我从更新com.android.tools.build:gradle:1.0.0
到时com.android.tools.build:gradle:1.1.1
,我得到以下警告:
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.1.0) and test app (22.0.0) differ.
如果使用以下排除项,则可以继续使用22.2.1:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
如果您依赖espresso-contrib
,则还需要排除。
使用支持库22.2.1,依赖关系再次被破坏。在发布新的亚军之前,请不要升级到22.2.1。
在最新版本的运行器0.3和规则0.3中,不再需要此答案。您可以简单地使用
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
最新的支持库。(22.2.0
截至撰写本文时)
compile 'com.android.support:appcompat-v7:22.2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
// com.android.support.test:testing-support-lib:0.1 // <-- causes issue
问题是与com.android.support:support-v4:22.1.1
发生冲突com.android.support.test:runner:0.2
(取决于com.android.support:support-v4:22.0.0
)。
com.android.support.test.espresso:espresso- core:2.1
依赖于com.android.support.test:runner:0.2
,因此也会导致相同的错误。
因此,此组合将起作用:
compile 'com.android.support:support-v4:22.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
…所以这个( 不带 'com.android.support.test:runner:0.2'
)也会这样:
compile 'com.android.support:support-v4:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
与Espresso文档所说的相反,您应该删除此依赖项:
androidTestCompile 'com.android.support.test:runner:0.2'
因为这是库版本冲突的原因。
您还应该更新至Android gradle插件1.1.1,因为该版本将告诉您确切的版本冲突,在这种情况下很有用。
问题内容: 在Android项目中,团队主要还是使用Eclipse并添加了一些第3方库,然后在运行gradle build时Android Studio无法在设备anf上运行,并出现错误: 对于不同的文件,以此类推10到20次 尝试过 和 和 对彼此而言 并编译’com.android.support:appcompat-v7:21.0.+’ Eclipse ADT没有问题。 如何使用Gradle
我无法编译该项目,编译时出现以下错误: 错误:任务': myApp: dexDebug'执行失败。 通用域名格式。Android石斑鱼类。常见的内部的LoggedErrorException:无法运行命令:C:\Program Files(x86)\Android\Android studio\sdk\build tools\21.0.2\dx。bat--dex--输出C:\Users\Andro
当我将android支持注释添加到我的依赖项时 我有一个错误: 错误代码:2输出:意外的顶级异常:com.android.dex.dexException:多个dex文件定义Landroid/Support/Annotation/Animres;在com.android.dx.merge.dexmerger.readsortabletypes(dexmerger.java:594)在com.and
如果我grep v4,我会在构建文件夹中看到两个文件。 我的gradle文件只包括以下支持库: 我很难理解r7库是如何被包括在内的。我运行了,当我重新运行AssembleDebug时,它总是出现在那里。 这是play services AAR bundle和v13库之间的不兼容吗?
我可以 ,它只有一个: <代码>设置。gradle如下: @garbriele:我更新了新问题,显示项目的
我敢肯定,不知怎么的,我添加了两倍的谷歌库。 多谢了。