【问题标题】:Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app and test app differ与项目“:app”中的依赖项“com.android.support:support-annotations”冲突。应用程序和测试应用程序的已解决版本不同
【发布时间】:2023-03-12 22:15:01
【问题描述】:

今天我在 android studio 开始了一个新项目。一切顺利,没有错误。添加项目后,我借助android studio中的Firebase助手工具将项目与Firebase实时数据库连接起来。

然后我得到这个错误:

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (23.0.0) and test app (25.4.0) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

我看到错误主要来自在我的应用程序级别 build.gradle 文件的末尾添加这一行。因为当我将其注释掉时,它构建得很好。

apply plugin: 'com.google.gms.google-services'

我对 gradle 构建系统了解不多。仅连接到 firebase 并添加 firebase-database 依赖项可能有什么问题。

我需要检查的资源

我的应用程序:build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.learning.insanes.chothavandar"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//    implementation 'com.google.firebase:firebase-database:11.6.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'

我的项目:build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

    标签: android firebase android-gradle-plugin google-play-services build.gradle


    【解决方案1】:

    试试这个:

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

    查看此link 以获得更好的理解

    【讨论】:

    • 请详细说明您的答案。我应该把这个放在哪里?我的问题究竟是什么?它将如何帮助解决我的问题?
    • 在你的 app build.gradle 中有这行代码androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'。换成我发的那个。它将排除报告的库模块。你有这个错误是因为你试图编译同一个库的两个不同版本。阅读我建议的链接以更好地了解您的问题
    • 谢谢。您的解决方案有效。如果您还有 test:runner 作为测试依赖项,请记得添加:androidTestImplementation ("com.android.support.test:runner:1.0.1") { exclude group: 'com.android.support', module: 'support-annotations' }
    【解决方案2】:

    在您的应用程序中:build.gradle 文件中的依赖项添加以下行,或者如果已经存在,请将其更改为:

    依赖{ .. 实施 'com.android.support:appcompat-v7:25.4.0' .. }

    【讨论】:

      猜你喜欢
      • 2018-10-11
      • 2016-08-02
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多