【问题标题】:Error While creating new project with android studio 3.0.1使用 android studio 3.0.1 创建新项目时出错
【发布时间】:2020-06-11 03:02:42
【问题描述】:

错误:任务 ':app:preDebugAndroidTestBuild' 执行失败。

与项目 ':app' 中的依赖项 'com.android.support:support-annotations' 冲突。应用程序 (26.1.0) 和测试应用程序 (27.1.1) 的已解决版本不同。详情请见https://d.android.com/r/tools/test-apk-dependency-conflicts.html

编辑:以下取自 cmets

以下是我的依赖项:

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.1.0' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.2' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 
    androidTestImplementation 'com.android.support:support-annotations:27.1.1' 
}

【问题讨论】:

  • 你能用`build.gradle`更新你的问题吗?
  • 依赖项 { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android .support.constraint:constraint-layout:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso -core:3.0.2' androidTestImplementation 'com.android.support:support-annotations:27.1.1' }
  • 这些是我在应用内实现的应用级依赖。我添加了最后一个 gradle androidTestImplementation 'com.android.support:support-annotations:27.1.1' 但错误没有解决。
  • 我已经回答了问题,您可以查看

标签: android


【解决方案1】:

基于documentation

您的应用 APK 和它的测试 APK 共享相同的类路径。因此,如果两个 APK 依赖于同一库的不同版本,您可能会收到构建错误。

所以解决方法是改变你的

com.android.support:appcompat-v7:26.1.0

com.android.support:appcompat-v7:27.1.1

【讨论】:

  • 太棒了!记得点击勾选按钮,这样它就被批准了,其他人也可以受益
【解决方案2】:

你也可以选择这个。

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

而不是这个,

androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    相关资源
    最近更新 更多