android - 迁移到 Androidx 问题。多个第三方库具有“资源重复价值”问题
问题描述
由于我的 gradle 文件中包含第三方库,我在迁移到 androidx 时遇到问题。要找到我遇到的问题:
创建了一个简单的项目,其中包括其中一些库。
编译项目没有问题
迁移到 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
解决方案
改变
实施 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
至
-alpha2
清理和重建 :)
推荐阅读
- python - PyCharm Nosetests 运行而不是运行
- macos - 本地端口转发到 MacOS 上的 wlan ip 地址
- angular - 使用 Angular http.get 获取非常大的 json 文件
- angular - 当数组用排序重新排序时,如何用角度/动画为 ngFor 列表中的数组的单个元素设置动画?
- database - Android SQlite 数据库表没有列错误
- php - 在 Codeigniter 4 的 CLI 命令上捕获 mysqli_sql_exception
- python-3.x - 试图在 DataFrame 分配数据帧中的切片副本上设置一个值
- python - 为什么十六进制字节数据 b'\x35' 在 Python 中被解释为 b'5'?
- flutter - 如果您的项目有 dart html 导入,如何在模拟器上运行颤振
- wordpress - 无法在多站点 Wordpress 上安装任何插件