android - 混合版本可能导致运行时崩溃

标签 android gradle android-gradle-plugin build.gradle

我知道这听起来可能是一个简单的问题,并且在 stackoverflow 上已经回答了好几次,但我是一个新手,无法从已经回答的线程中找到有效的解决方案。我的 gradle 我收到这个错误:

    All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found versions
26.1.0, 25.3.1, 25.2.0. Examples include `com.android.support:animated-vector
drawable:26.1.0` and `com.android.support:cardview-v7:25.3.1`

Error screenshot

该应用程序构建良好,也可以在 API 22 等少数设备上运行,但在测试时我发现该应用程序在 API 19 和其他一些较低的 API 上崩溃。

这是我的gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "*******"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/activation.jar')
    compile 'com.google.firebase:firebase-database:11.2.2'
    compile 'com.google.firebase:firebase-auth:11.2.2'
    compile 'com.google.firebase:firebase-storage:11.2.2'
    compile 'com.google.android.gms:play-services:11.2.2'
    compile 'com.firebase:firebase-client-android:2.3.1'

    compile 'com.android.support:appcompat-v7:26.1.0'    << Error with this line

    compile 'com.android.support.constraint:constraint-layout:+'
    compile 'com.android.support:multidex:1.0.1'
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.github.bumptech.glide:glide:4.2.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.jd-alexander:library:1.1.0'
    compile 'com.google.maps.android:android-maps-utils:0.5'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
}

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

最佳答案

首先将您的 targetSdkVersion 更改为 26。您应该为 android 支持库使用相同的版本。您应该按以下方式更正您的版本:

compile 'com.android.support:appcompat-v7:26.1.0'  
compile 'com.android.support.constraint:constraint-layout:26.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:support-v4:26.1.0

由于您没有显式编译 cardView,因此可能存在使用 25.3.1 版本的第三方库。要解决此问题,还要编译以下版本:

com.android.support:cardview-v7:26.1.0    

并尽量避免在依赖项中使用 + 符号,它们会加载一堆不必要的版本。

关于android - 混合版本可能导致运行时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47594177/

相关文章:

java - 使用动画移动按钮并在之后更改它们的位置

android - AppCompat 工具栏不显示

android - 由于库不在项目中,应用已从 PlayStore 中删除

android - Gradle android,如何排除单个单元测试

android - 选择构建类型时如何区分构建风格?

android - 已签名的 apk 在 google play 商店中的兼容性为 0

Android 创建类似 Spotify 的 slider 菜单

android - AdMob 地址验证 PIN - 错误的字母?

android - 枚举中的变量初始化,或在编译时防止枚举丢失案例

android - 为什么 jackOptions 在 Android Studio 2.2 Preview 1 中不起作用?