与项目':app'中的依赖'com.android.support:support-annotations'冲突。应用和测试应用的已解决版本不同

时间:2017-11-30 13:23:10

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

今天我在android studio开始了一个新项目。一切顺利,没有错误。添加项目后,我使用Android工作室中的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.

enter image description here

我发现错误主要来自在我的应用级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
}

2 个答案:

答案 0 :(得分:2)

试试这个:

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

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

答案 1 :(得分:-1)

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

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