【问题标题】:android.support libraries not compatible together after updationandroid.support 库在更新后不兼容
【发布时间】:2018-04-15 09:24:31
【问题描述】:

我刚刚更新了我的 gradle 插件,然后收到警告告诉我更新我的一些实现。我刚刚升级了两个

com.android.support:appcompat

com.android.support:design

到 27.1.1。但现在我收到警告说

All com.android.support libraries must use the exact same version 
specification (mixing versions can lead to runtime crashes). Found versions 
27.1.1, 26.1.0. Examples include com.android.support:animated-vector-
drawable:27.1.1 and com.android.support:customtabs:26.1.0
There are some combinations of libraries, or tools and libraries, that are 
incompatible, or can lead to bugs. One such incompatibility is compiling 
with a version of the Android support libraries that is not the latest 
version (or in particular, a version lower than your targetSdkVersion).

这里是gradle的app模块中的依赖

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "aheschl.studyup"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 9
        versionName '3.1.1'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-database:15.0.0'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    implementation 'com.google.android.gms:play-services-ads:15.0.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'
    implementation 'com.android.support:design:27.1.1'
}

我了解其中一个库需要升级版本,但我找不到哪些库。我可以选择只是抑制警告,但我的应用程序正在生产中,我不想这样做。感谢您的帮助

【问题讨论】:

    标签: android gradle


    【解决方案1】:

    在你的根项目中加入这样的东西:

    Map<String,String> versionOverrides = [
            'com.android.support:support-v7' : '27.1.1'
            ...
    ]
    
    def overrideDependencies = { Project project ->
        project.configurations.all {
            // See https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
            resolutionStrategy {
                eachDependency { DependencyResolveDetails details ->
                    String overrideVersion = versionOverrides.get(details.requested.group + ":" + details.requested.name)
                    if (overrideVersion != null && details.requested.version != overrideVersion) {
                        logger.debug("Overriding dependency ${details.requested.group}:${details.requested.name} " +
                                "version ${details.requested.version} --> $overrideVersion")
                        details.useVersion overrideVersion
                    }
                }
            }
        }
    }
    
    subprojects { project ->
        overrideDependencies(project)
    }
    

    【讨论】:

      【解决方案2】:

      冲突的依赖可能来自 Firebase 和 Google play 服务库。你需要检查它:

      ./gradlew app:dependencies
      

      然后您可以通过将支持库添加到您的依赖项块来覆盖它们。你不需要使用exclude

      【讨论】:

      • 您是否有机会通过示例代码展示此解决方案?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多