前言
今天遇到个奇葩的问题,刚刚打包还好好的,突然就爆出:
Error:Execution failed for task ':app:prepare Debug Android Test Dependencies'.
> Dependency Error. See console for details.
借助我英语二级的水平,颤颤巍巍打开有道翻译了下:
错误:任务执行失败:app:准备调试Android测试依赖项。
依赖性错误。有关详细信息,请参阅控制台。
相信各位看得很明白,所以,依照惯例,我还是去百度了下。
参考方法
一、 11个支持
I got the same probleme,when I add the following code in my app’s build.gradle within android { },that’s ok.
我也遇到了同样的问题,在我把下面的代码放到app的build.gradle的android方法下的时候,这个问题就解决了。(自译,谅)
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
虽然我试了下,没啥用,但11个支持可能有用,但我这边问题比较奇葩吧。各位可以试一下。
二、 8个支持
You need to add this line to your dependencies:
您需要将这一行添加到您的依赖项中。(有道)
androidTestCompile 'com.android.support:support-annotations:25.0.0'
to force using the latest version of library
You can also try to exclude conflict packages like I did for espresso-contrib library
使用最新版本的库。
您也可以尝试排除冲突包,就像我为espresso- b库所做的那样。(有道)
dependencies {
ext.JUNIT_VERSION = '4.12'
ext.AA_VERSION = '4.0.0'
ext.SUPPORT_VERSION = '24.1.1'
ext.ESPRESSO_VERSION = '2.2.2'
androidTestCompile "com.android.support:support-annotations:$SUPPORT_VERSION"
androidTestCompile "com.android.support.test.espresso:espresso-core:$ESPRESSO_VERSION"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile "com.android.support.test.espresso:espresso-intents:$ESPRESSO_VERSION"
/**
* AccessibilityChecks
* CountingIdlingResource
* DrawerActions
* DrawerMatchers
* PickerActions (Time and Date picker)
* RecyclerViewActions
*/
androidTestCompile("com.android.support.test.espresso:espresso-contrib:$ESPRESSO_VERSION") {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-v7'
exclude group: 'com.android.support', module: 'design'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
这个答案就很有质量了,虽然我试了下也没用。
三、 1个支持
This happen because of library version conflict in the debug app and test app. Add this under android{} tag
这问题是因为引入库的版本在调试和测试App两个环境中存在冲突,在app的(build.gradle)下面的androi{}标签里面添加这个(自译,谅)
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:24.1.1'
}
}
三个解决方法都没有解决我的问题,这里记录下来,可能会解决各位的问题。
自力更生
习惯使然,让我遇到问题就想要百度求支援,但问题已经告诉我们了依赖性错误。有关详细信息,请参阅控制台。所以,我还是摸索着看了看按钮:
我上看下看左看右看,也就只有右列的第四个像是控制台输出,点开还真是:
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library
:app:prepareComAndroidSupportMultidexInstrumentation101Library
:app:prepareDebugAndroidTestDependencies
Conflict with dependency 'com.android.support:multidex' in project ':app'. Resolved versions for app (1.0.2) and test app (1.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:prepareDebugAndroidTestDependencies'.
> Dependency Error. See console for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 17s
毕竟也是英语二级的人,看了半天还是看到了问题所在
Conflict with dependency 'com.android.support:multidex' in project ':app'. Resolved versions for app (1.0.2) and test app (1.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
然后去build.gradle里面把版本号改成 1.0.1,重新编译就OK了。
总结
还是要靠自己,出了问题先自己琢磨怎么解决,实在不行再去求助,这样更能增强抵抗力,遇到问题才能不慌。————来自求助一天没解决,自己看了几分钟解决的人