【问题标题】:All com.android.support libraries must use the exact same version specification (mixing version can lead to runtime crashes)所有 com.android.support 库必须使用完全相同的版本规范(混合版本会导致运行时崩溃)
【发布时间】:2019-04-07 07:23:02
【问题描述】:

我在 build.gradle 中发现了一个错误问题。有消息给我“所有com.android.support库必须使用完全相同的版本规范(混合版本会导致运行时崩溃)。并且“实现”底部有一条红线com.android.support:appcompat-v7:28.0.0'"。不知道哪里出错了。

谢谢

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'
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation 'com.android.support:palette-v7:28.0.0'
implementation "com.android.support:cardview-v7:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"

//Firebase Dependencies
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-firestore:18.0.1'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-ads:17.1.3'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-appindexing:17.1.0'
implementation 'com.google.firebase:firebase-ads:17.2.0'

implementation 'com.google.android.gms:play-services-ads:17.2.0'

implementation 'com.artjimlop:altex-image-downloader:0.0.4'
implementation 'com.yalantis:ucrop:2.2.0'

implementation 'com.github.danimahardhika:cafebar:1.3.1'
implementation 'com.github.qiugang:EditTag:v1.2.4-beta2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.airbnb.android:lottie:2.6.0'
implementation 'com.github.chyrta:AndroidOnboarder:0.7'

//Error Fixer
implementation 'com.android.support:multidex:1.0.3'

implementation 'com.android.support:support-vector-drawable:28.0.0'
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'

【问题讨论】:

  • 到目前为止,这个问题被问了很多次,几乎不可能在 1 分钟的搜索中找不到。
  • 并且有 4 个重复的依赖项......这几乎不是 MCVE

标签: android firebase build.gradle


【解决方案1】:

您的 gradle 依赖项需要返工:

  1. 清理重复的依赖项,每行只添加一次!

行:

  • implementation 'com.android.support:appcompat-v7:28.0.0'
  • implementation "com.android.support:design:28.0.0"

是两次。每个只保留一次!

  1. 每个库只使用一个版本定义。 Firebase 核心导入了两个不同的版本:
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.7'

选择两行之一。

  1. 您的依赖项不应有不同的版本。您有许多库使用其他版本的com.android.support 组件,这可能会导致此错误。

例如:

  • 'com.artjimlop:altex-image-downloader:0.0.4' 使用com.android.support:appcompat-v7:23.1.0here

  • 'com.yalantis:ucrop:2.2.0'使用com.android.support:appcompat-v7:24.2.0here

  • 'com.github.danimahardhika:cafebar:1.3.1' 使用com.android.support:designcom.android.support:cardview-v7here

  • 'com.github.qiugang:EditTag:v1.2.4-beta2' 使用com.android.support:recyclerview-v7com.android.support:appcompat-v7here

  • 几乎所有 3rd 方 github 库的列表还在继续。

您可以使用以下配置来排除所有依赖项。

configurations {
  all*.exclude module: "appcompat-v7"
  all*.exclude module: "recyclerview-v7"
  all*.exclude module: "design"
  all*.exclude module: "cardview-v7"
  // ... etc in case there are extra dependencies
}

或者更好的是,您可以通过每个依赖项并排除导致重复的确切库:

即。对于'com.artjimlop:altex-image-downloader:0.0.4',您应该将implementation 'com.artjimlop:altex-image-downloader:0.0.4' 更改为:

implementation ('com.artjimlop:altex-image-downloader:0.0.4') {
   exclude group: 'com.android.support', module: 'appcompat-v7'
   // for more than one just add it in a new line ie.
   // exclude group: '<first part till : symbol>', module: '<second part between : symbol and version>'
}

如果您想进一步了解依赖关系问题,请阅读这篇文章here

【讨论】:

    【解决方案2】:

    你一定看到这样的红线吧?将鼠标指针悬停在红线上,您将看到这样的对话框。查找哪些库仍然旧(在我的情况下是 cardview)在 gradle 中添加该库的最新版本,您的问题可能会得到解决。

    如果仍然没有,那么我发现您正在使用旧的 Firebase 库,请将它们也更新到最新版本。

    【讨论】:

    • 我将所有 com.android.support 更改为最新版本。但不工作。
    • 实现 'com.android.support:appcompat-v7:28.0.0' 实现 'com.android.support.constraint:constraint-layout:1.1.3' 实现 'com.android.support:设计:28.0.0' 实施 'com.android.support:palette-v7:28.0.0' 实施 'com.android.support:cardview-v7:28.0.0' 实施 'com.android.support:recyclerview-v7: 28.0.0'
    【解决方案3】:

    错误消息非常清楚,“所有 com.android.support 库必须使用完全相同的版本规范”。例如,你有这样的:

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.7'
    

    您正在尝试构建同一个库的 2 个不同版本,16.0.1 和 16.0.7。这可能导致运行时崩溃。选择您要保留的版本并删除另一个。例如,如果您想要版本 16.0.7,请将这两行替换为:

    implementation 'com.google.firebase:firebase-core:16.0.7'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 2019-07-05
      • 2017-11-12
      相关资源
      最近更新 更多