【问题标题】:support libraries must use the exact same version specification [duplicate]支持库必须使用完全相同的版本规范[重复]
【发布时间】:2018-07-17 17:11:43
【问题描述】:

我尝试使用特定活动运行我的应用程序,但我正在发生连续崩溃。

我已查明与 appcompat 版本有关的错误。但是,我不确定如何修复此错误,即在同一版本上获取我的所有依赖项。

我想知道是否有快速解决方法可以做到这一点?如果没有,有哪些步骤可以确保它们都在正确/相同的版本上?

build.gradle(模块:app)

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.benchalmers.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        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:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.volley:volley:1.1.0'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}

这是给我的错误:

所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 27.0.2、26.1.0。例子包括 com.android.support:support-compat:27.0.2 和 com.android.support:animated-vector-drawable:26.1.0 少... (⌘F1) 有一些库或工具和库的组合,它们 不兼容,或者可能导致错误。一种这样的不兼容性是 使用不支持的 Android 支持库版本进行编译 最新版本(或者特别是低于您的 targetSdkVersion。)

任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 从终端运行gradlew dependencies。哪些库取决于任何支持库的版本 27.0.2?

标签: android android-support-library


【解决方案1】:

像这样更新你的依赖:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:design:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:27.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:recyclerview-v7:27.0.2'
    compile 'com.android.support:cardview-v7:27.0.2'
    compile 'com.android.volley:volley:1.1.0'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}

就像错误消息所说:在您的项目中发现支持库的版本冲突。您需要做的是“修复”它,然后确保您的支持库版本相同(最好是最新版本)。

为了简化这个过程,您还可以使您的代码如下所示:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    def supportLibraryVersion = "27.0.2"
    implementation "com.android.support:support-v4:$supportLibraryVersion"
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support:support-v4:$supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
    compile "com.android.support:cardview-v7:$supportLibraryVersion"

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    compile 'com.android.volley:volley:1.1.0'

    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}

另外,正如 Michael Dodd 所建议的,为了使用支持库版本 27.0.2,您还需要发送 compileSdkVersion

android {
    ...
    compileSdkVersion 27
    ...
}

【讨论】:

  • 在这种情况下,OP 还需要将 compileSdkVersiontargetSdkVersion 增加到 27。
猜你喜欢
  • 2018-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-12
相关资源
最近更新 更多