混合版本可能导致运行时崩溃。帮助找到原因

时间:2018-07-30 16:11:37

标签: android build.gradle android-support-library

我所有的依赖项都从27版开始,但是构建任务仍在完成,但有一个异常:

  

错误:所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本27.1.1、25.4.0。示例包括com.android.support:animated-vector-drawable:27.1.1和com.android.support:cardview-v7:25.4.0 [GradleCompatible]

我知道我可以添加

  lintOptions {
      abortOnError false
  }

它可以解决我的问题,但我想确定原因。

这是我的build.gradle文件:

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

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "my.company.app"
        minSdkVersion 19
        targetSdkVersion 27
        multiDexEnabled true
        versionCode 1
        versionName "0.10.8"
        vectorDrawables.useSupportLibrary = true
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

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

            buildConfigField("String", "ENV_URL_PREFIX", "\"https://\"")
            buildConfigField("String", "ENVIRONMENT", "\"release\"")
        }

        staging {
            initWith debug

            buildConfigField("String", "ENV_URL_PREFIX", "\"https://staging.\"")
            buildConfigField("String", "ENVIRONMENT", "\"staging\"")
        }

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

            buildConfigField("String", "ENV_URL_PREFIX", "\"https://dev.\"")
            buildConfigField("String", "ENVIRONMENT", "\"dev\"")
        }
    }

    flavorDimensions "app"
    productFlavors {
        _Live {
            dimension "app"
            buildConfigField("String", "TYPE", "\"live\"")
        }
        _Test {
            dimension "app"
            buildConfigField("String", "TYPE", "\"test\"")
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'lib/x86_64/darwin/libscrypt.dylib'
        exclude 'lib/x86_64/freebsd/libscrypt.so'
        exclude 'lib/x86_64/linux/libscrypt.so'
    }
}

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

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:gridlayout-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'

    implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'
    implementation 'me.dm7.barcodescanner:zxing:1.8.4'
    implementation 'com.crowdfire.cfalertdialog:cfalertdialog:1.1.0'

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-places:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.zxing:zxing-parent:3.3.3'
    implementation 'com.google.zxing:core:3.3.2'
    implementation 'com.google.guava:guava:22.0'

    implementation project(':mobile_api') // a module compiled with java plugin

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
}

我的想法是,某些依赖项迁移了版本为25.4.0的com.android.support库。 如有任何建议,我将不胜感激。 预先感谢!

3 个答案:

答案 0 :(得分:1)

您正在使用此库'com.crowdfire.cfalertdialog:cfalertdialog:1.1.0', 然后依次使用dependency'com.android.support:cardview-v7:25.4.0' 也许这是冲突的原因。

答案 1 :(得分:0)

将其添加到根级别build.gradle的末尾:

configurations.all { 
    resolutionStrategy.eachDependency { DependencyResolveDetails details -> 
        def requested = details.requested 
        if (requested.group == 'com.android.support')  { details.useVersion '27.x.x' } 
        } 
    }

答案 2 :(得分:0)

要解决此问题,我添加了一个依赖项

implementation 'com.android.support:cardview-v7:27.1.1'
在我的build.gradle中的

覆盖了25.4.0。因此,您无需查找包含中断库的依赖项。