由于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
答案 0 :(得分:2)
更改
实现'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
到
-alpha2
引导并重建:)
答案 1 :(得分:0)
您在迁移后是否尝试过?
- Clean and Build or gradle clean build assemble
- Invalidate and restart Android Studio