【问题标题】:Gradle gives compatibility error when adding firebaseGradle 在添加 firebase 时出现兼容性错误
【发布时间】:2019-04-01 09:08:52
【问题描述】:

所以,我刚刚创建了一个新项目,在添加任何新库或任何东西之前,我刚刚添加了 firebase 库,一旦我同步了 gradle,它就会给我一个错误,说混合 android 库会导致 appcompat 出现问题图书馆。

我在这里做错了什么?为什么我会收到这个错误,我该如何摆脱它?

这是我的 gradle 文件的源代码:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.femindharamshi.codifyadmin"
            minSdkVersion 21
            targetSdkVersion 28
            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:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        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'
        implementation 'com.google.firebase:firebase-core:16.0.4'

    }

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

【问题讨论】:

    标签: android gradle error-handling libraries mixing


    【解决方案1】:

    添加这个实现:

    implementation 'com.android.support:support-media-compat:28.0.0' 
    

    说明: 您可以在错误中看到您当前使用的库版本不同。在示例之后的部分中,它向您展示了哪一个。尽管您可能认为您没有使用它。您在主库中间接使用它。因此,如果有较低的颠覆,您必须显式升级库

    【讨论】:

      【解决方案2】:

      将此行添加到您的 appcompat 依赖项上方

      //noinspection GradleCompatible
      

      【讨论】:

      • 这不是解决方案。它只是避免问题
      • 我遇到了同样的问题。东这对我有帮助。
      • 是的,您在运行应用程序时可能会遇到错误。必须有相同版本的支持库。
      • 阅读我的回答。添加工作室建议您使用最新版本的所有实现。它会解决你的问题
      • 是安卓新版本的问题。不管你使用什么依赖,它都会给你那个错误
      【解决方案3】:

      你必须检查/修复依赖冲突,

      • ./gradlew androidDependencies./gradlew app:dependencies
      • 然后您将看到在不同版本的依赖项之间重复的模块。

      解决方案

      1. 强制解决:

        //force a resolution
        
        configurations.all {
          resolutionStrategy.force 'com.android.support:support-media-compat:28.0.0'
        }
        
      2. 排除重复的模块

        //excluding a module!
        
        implementation ("com.android.support:appcompat-v7:28.0.0") {
           exclude group: 'com.android.support', module: 'support-media-compat'
        }
        

      更新强制支持库

      ext {
          supportLibVersion = '28.0.0'
      }
      
      dependencies {
          // ... Other dependencies 
          implementation "com.android.support:appcompat-v7:$supportLibVersion"
          implementation ("com.android.support:support-v4:$supportLibVersion"){
              force = true
          }
          implementation ("com.android.support:exifinterface:$supportLibVersion"){
              force = true
          }
      }
      

      【讨论】:

      • 如果我执行选项 2,错误出现在 androidTestImplementation 'com.android.support.test:runner:1.0.2' 上,但我不知道那是什么
      • @UrvikShah 检查我的答案更新,使用 Force Support libs 解决方案,希望能解决您的问题。
      【解决方案4】:

      你可以看到this answer。只需要这样做:

      implementation ('com.google.firebase:firebase-core:16.0.4') {
          exclude group: "com.android.support"
      }
      

      【讨论】:

      • 你使用哪个版本的gms插件?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多