android - 编译时"All com.android.support libraries must use the exact same version specification"android.support :appcompat-v7:25. 2.0

标签 android android-studio gradle

将 Android Studio 更新到版本 3.1.2 后,我在应用的 build.gradle 中收到错误:

All com.android.support libraries must use the exact same version specification (...). Found versions 28.0.0-alpha1, 26.1.0. Examples include com.android.support:asynclayoutinflater:28.0.0-alpha1 and com.android.support:animated-vector-drawable:26.1.0

这是我的gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "org.hopto.****.musicplayer"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.cleveroad:audiowidget:0.9.0'
    compile 'com.google.android.gms:play-services-ads:10.2.0'
    compile 'com.android.support:recyclerview-v7:+'
    testCompile 'junit:junit:4.12'
}

我尝试通过添加以下行来解决此问题:

compile 'com.android.support:asynclayoutinflater:25.0.0'
compile 'com.android.support:animated-vector-drawable:25.0.0'

我也尝试过使用不同的版本,例如 25.2.0 和 25+,但都没有用。

最佳答案

您正在使用以下支持库:

compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:recyclerview-v7:+' //error here

如您所见,您的 recyclerview 库使用的是“+”,这是可用的最新版本,即 28.0.0-alpha1 或 26.1.0(稳定版)。对于其余部分,您使用的是 25.2.0,因此出现版本不匹配的错误。

解决方案是将 recyclerview 版本更改为 25.2.0 或将所有内容更改为 26.1.0(包括 recyclerview)。

旁注:您应该避免在版本号中使用“+”,因为您可能会在库更新时出现意外行为。

关于android - 编译时"All com.android.support libraries must use the exact same version specification"android.support :appcompat-v7:25. 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50665535/

相关文章:

android - 文件或数据库

android - 在 Android Studio 的 Flutter 应用中找不到已连接的设备

java.lang.Boolean 无法转换为 ba.store.models.Merchants

Kotlin-multiplatform:ShadowJar gradle 插件创建空 jar

android - 使用 gradle (android) 包含已编译的可执行文件和库

java - 如何从命令行使用 gradle 运行测试套件

java - Android 空指针异常。为什么?

android - 如何延迟从另一个 Activity 调用 Activity ?

java - Camera2 API 相机管理器 可疑类型转换

android - 很难为 Android 编译 tess-two