首页 > 解决方案 > 迁移到 Androidx 问题。多个第三方库具有“资源重复价值”问题

问题描述

由于我的 gradle 文件中包含第三方库,我在迁移到 androidx 时遇到问题。要找到我遇到的问题:

输出 :

Android resource compilation failed
Output:  /Development/Android/trunk_deleteme/projects/MyApplication2/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:1550: error: duplicate value for resource 'attr/orientation' with config ''.
/Development/Android/trunk_deleteme/projects/MyApplication2/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:1550: error: resource previously defined here.
/Development/Android/trunk_deleteme/projects/MyApplication2/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:1816: error: duplicate value for resource 'attr/visibility' with config ''.
/Development/Android/trunk_deleteme/projects/MyApplication2/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:1816: error: resource previously defined here.

Command: /Users/a/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/2d51c190036eff4bb9de8b002a634480/aapt2-3.2.1-4818971-osx/aapt2 compile --legacy \
        -o \
        /Development/Android/trunk_deleteme/projects/MyApplication2/app/build/intermediates/res/merged/debug \
        /Development/Android/trunk_deleteme/projects/MyApplication2/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0

我的 Gradle 文件:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {

    dexOptions {
        jumboMode true
    }


    compileSdkVersion 28
    defaultConfig {
        applicationId "com.a.myapplication"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation 'com.appeaser.sublimepickerlibrary:sublimepickerlibrary:2.1.2'

}

gradle.properties

org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.useAndroidX=true
android.enableJetifier=true

我知道这些问题可以从第三方库所有者那里修复,但其中一些不会很快提供新版本。

问题是:

有没有办法从我这里解决这些问题,而不是等待第三方库所有者更新他们的代码?

编辑:以下是依赖树的一部分

+--- com.appeaser.sublimepickerlibrary:sublimepickerlibrary:2.1.2
|    +--- androidx.appcompat:appcompat:1.0.0-rc01 -> 1.1.0-alpha01 (*)
|    +--- androidx.legacy:legacy-support-v4:1.0.0-rc01
|    |    +--- androidx.core:core:1.0.0-rc01 -> 1.1.0-alpha01 (*)
|    |    +--- androidx.media:media:1.0.0-rc01
|    |    |    +--- androidx.annotation:annotation:1.0.0-rc01 -> 1.0.0
|    |    |    +--- androidx.core:core:1.0.0-rc01 -> 1.1.0-alpha01 (*)
|    |    |    \--- androidx.versionedparcelable:versionedparcelable:1.0.0-rc01 -> 1.1.0-alpha01 (*)
|    |    +--- androidx.legacy:legacy-support-core-utils:1.0.0-rc01 -> 1.0.0 (*)
|    |    +--- androidx.legacy:legacy-support-core-ui:1.0.0-rc01 -> 1.0.0 (*)
|    |    \--- androidx.fragment:fragment:1.0.0-rc01 -> 1.1.0-alpha02 (*)
|    +--- androidx.gridlayout:gridlayout:1.0.0-rc01
|    |    +--- androidx.core:core:1.0.0-rc01 -> 1.1.0-alpha01 (*)
|    |    \--- androidx.legacy:legacy-support-core-ui:1.0.0-rc01 -> 1.0.0 (*)
|    \--- androidx.annotation:annotation:1.0.0-rc01 -> 1.0.0
\--- androidx.multidex:multidex:2.0.0

标签: androidgradleandroidx

解决方案


改变

实施 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'

-alpha2

清理和重建 :)


推荐阅读