混合使用不同版本可能导致运行时崩溃。

3

我知道这可能是一个简单的问题,而且在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`

错误截图

该应用程序可以成功构建,并且在一些设备上(如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'

将您的目标 SDK 版本更改为 26。 - Raj
您的错误日志依赖版本低于目标版本。 - Raj
@Raj 改成 26 没有起作用。 - usama ahsan
你有一个版本为26.0.1的构建工具吗? - Raj
你使用了哪个集成开发环境(IDE)以及该IDE的版本? - Raj
显示剩余5条评论
1个回答

2

首先将你的targetSdkVersion更改为26。你应该使用同样的版本来支持安卓库。你应该按照以下要求更正你的版本:

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    

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接