【问题标题】:Gradle error when adding the support library添加支持库时出现 Gradle 错误
【发布时间】:2018-03-12 18:17:24
【问题描述】:

我正在尝试让我的应用使用PreferenceFragmentCompat

我的依赖:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:preference-v7:25.4.0'
compile 'com.android.support:preference-v14:25.4.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.google.firebase:firebase-ads:11.8.0'
compile 'io.github.kobakei:ratethisapp:1.2.0'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
compile 'com.github.chrisbanes:PhotoView:2.1.3'
testCompile 'junit:junit:4.12'

}

我新添加的内容:

compile 'com.android.support:preference-v7:25.4.0'
compile 'com.android.support:preference-v14:25.4.0'

错误是关于第一个依赖:

编译'com.android.support:appcompat-v7:25.3.1'

上面写着:

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 25.4.0、25.3.1。示例包括 com.android.support:animated-vector-drawable:25.4.0 和 com.android.support:cardview-v7:25.3.1 less... (Ctrl+F1) 有一些库或工具和库的组合是不兼容的,或者可能导致错误。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本(或者特别是低于您的 targetSdkVersion 的版本)进行编译。

【问题讨论】:

  • 您可以尝试listing your dependencies 找出不同的支持库版本是从哪里引用的,这可以帮助您弄清楚如何修复您的配置。
  • 最新的是 27.1.0。您还可以使用 gradlew.bat app:dependencies 或 ./gradlew app:dependencies 检查哪个依赖库使用不同版本,具体取决于操作系统

标签: android


【解决方案1】:

它准确地告诉你,所有

com.android.support:**

应该使用相同的版本

改成:

compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:preference-v7:25.4.0'
compile 'com.android.support:preference-v14:25.4.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.android.support:support-vector-drawable:25.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.google.firebase:firebase-ads:11.8.0'
compile 'io.github.kobakei:ratethisapp:1.2.0'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
compile 'com.github.chrisbanes:PhotoView:2.1.3'

【讨论】:

  • 你尝试过干净的项目吗?使缓存无效/重新启动?
  • 听起来很奇怪,所以我用我上面写的完全相同的依赖项为我自己运行它。一切正常(除了它无法解决photoview,但这无关紧要,所以我删除了它)。需要注意的是,如果您使用的是 lib 版本 25,则需要使用 compileSdk 25,如果 24...
【解决方案2】:

始终使用/更新相同的支持库版本,因此将您的代码替换为:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile ('com.android.support:appcompat-v7:25.4.0'){force true}
compile ('com.android.support:design:25.4.0'){force true}
compile ('com.android.support:support-v4:25.4.0'){force true}
compile ('com.android.support:preference-v7:25.4.0'){force true}
compile ('com.android.support:preference-v14:25.4.0'){force true}
compile ('com.android.support:cardview-v7:25.4.0'){force true}
compile ('com.android.support:support-vector-drawable:25.4.0'){force true}
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.google.firebase:firebase-ads:11.8.0'
compile 'io.github.kobakei:ratethisapp:1.2.0'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
compile 'com.github.chrisbanes:PhotoView:2.1.3'
testCompile 'junit:junit:4.12'
}

要获得重复的依赖报告检查这个SO

【讨论】:

    猜你喜欢
    • 2014-05-06
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多