Gradle版本冲突

时间:2018-06-21 10:29:26

标签: android gradle version conflicting-libraries

我的build.gradle很好,直到我尝试将sdk版本(更新为27)和lib版本更新为止。

在我的build.gradle中,我现在有:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'

    implementation 'com.google.firebase:firebase-crash:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    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'
}

我收到一条错误消息:

  Please fix the version conflict either by updating the version of the google-services plugin 
(information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 15.0.1.

..但是您看到的是15.0.1。

我在

下也有红色的下划线
implementation 'com.android.support:appcompat-v7:27.1.1'

当我将鼠标悬停在上面时,我得到:

all support libraries must use the exact same version ... found versions 27.1.1 and 26.1.0

但我看不到任何26.1.0。

我在做什么错了?

4 个答案:

答案 0 :(得分:2)

您需要更新主要的build.gradle文件:

如果您使用的是Android Studio 3.1.2,则您的build.gradle文件应如下所示:

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

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.1' // you need to update this most probably.
    }
}

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

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

,而在您模块的build.gradle文件implement的最新版本中,custom tabs27.1.1

'com.android.support:customtabs:27.1.1'

答案 1 :(得分:1)

转到android studio并按File-> Invalidate Caches / Restart在出现的窗口中按Invalidate and Restart,问题可能出在缓存版本中, 为我工作)

答案 2 :(得分:0)

我也有类似的问题。更新后。幸运的是,经过很多线程后,这个问题得到解决。

在使用Firebase时,建议您更新crashlytics。不推荐使用旧版本。

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1' 
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
    }
}

现在要依赖

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.app.abc"
        minSdkVersion 19
        targetSdkVersion 27
        ......
        }
}

dependencies {
    api fileTree(dir: 'libs', include: ['*.jar'])
    api 'com.android.support:appcompat-v7:27.1.1'
    api 'com.android.support:support-v4:27.1.1'
    api 'com.android.support:design:27.1.1'


    //crash analytics
    api 'com.crashlytics.sdk.android:crashlytics:2.9.3'
    api 'com.google.firebase:firebase-crash:11.8.0'

    //Google Maps. You can avoid this, as I was using location services as well
    api 'com.google.android.gms:play-services-maps:12.0.1'
    api 'com.google.android.gms:play-services-places:12.0.1'
    api 'com.google.android.gms:play-services:12.0.1'
    api 'com.google.android.gms:play-services-location:12.0.1'

  }

答案 3 :(得分:0)

该错误表明您存在依赖关系冲突。我曾经遇到过一次表达测试。您要做的是排除expresso测试库的其他依赖项。 This stack post may help

androidTestCompile ('com.android.support.test.espresso:espresso-core:3.0.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'design'
}