【问题标题】:Mixing versions can lead to runtime crashes. Help to find a reason混合版本可能导致运行时崩溃。帮忙找个理由
【发布时间】:2018-07-31 00:52:04
【问题描述】:

我的所有依赖项都从 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 库。 我将不胜感激任何建议。 提前致谢!

【问题讨论】:

  • 签入 mobile_api 项目构建 gradle 文件并将其也更改为 27.1.1。也可以使用 CMD + SHIFT + F 并使用 25.4.0 搜索,如果您在项目所依赖的任何模块中的项目中找到任何文件,请将其更改为 27.1.1

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


【解决方案1】:

您正在使用此库“com.crowdfire.cfalertdialog:cfalertdialog:1.1.0”, 它又使用dependency'com.android.support:cardview-v7:25.4.0' 也许这就是冲突的原因。

【讨论】:

    【解决方案2】:

    将此添加到根级别 build.gradle 的最后:

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

    【讨论】:

      【解决方案3】:

      为了修复它,我添加了一个依赖项

      implementation 'com.android.support:cardview-v7:27.1.1'
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-27
        • 1970-01-01
        相关资源
        最近更新 更多