【问题标题】:Gradle Version conflictsGradle 版本冲突
【发布时间】:2018-06-21 10:29:26
【问题描述】:

在我尝试更新 sdk 版本(到 27)和 lib 版本之前,我的 build.gradle 一直很好。

在我的 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。

我做错了什么?

【问题讨论】:

  • 你能发布完整的 build.gradle 文件吗?
  • 它通常指定具有版本的库的名称。一些依赖在内部使用的是旧版本,只需将提到的库版本为 26 并将其添加到版本 27
  • 尝试使用 com.android.support 包下每个库中的相同版本
  • "但我没有看到任何 26.1.0" 那么您可能通过其他一些依赖项间接依赖它。您可以从命令行运行gradlew app:dependencies 来获取项目的依赖关系树。

标签: android gradle version conflicting-libraries


【解决方案1】:

你需要更新你的主 bu​​ild.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 tabs 在你的情况下是27.1.1

'com.android.support:customtabs:27.1.1'

【讨论】:

  • 感谢 Umair,'com.google.gms:google-services:4.0.1' 成功了(我有一个旧版本)。现在我只需要修复红色摆动线的问题
  • 是的,但红色的摆动线是由于我在库中有 Gradle__com_android_support_customtabs_26_1_0.xml。我需要更新它,但不知道为什么我首先遇到问题以及如何解决
  • @j3App 您可以删除该文件并再次同步它会解决问题。您遇到问题的原因很可能是您之前使用的是 26 版?
  • 删除和重新同步对我没有用。我必须在我的 build.gradle 中添加“实现'com.android.support:customtabs:27.1.1'”。反正;非常感谢您帮助我
  • @j3App 它确实对我有用。 Android 永远不会让你惊讶......快乐编码 :)
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    当您使用 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'
    
      }
    

    【讨论】:

    • 谢谢 Sreehari,我正要添加 CrashLytics。我也将它用于我的其他应用程序
    【解决方案4】:

    该错误表明您存在依赖冲突。我曾经在 expresso 测试中遇到过这个问题。您要做的是排除 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'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多