android - 启用 androidX 会导致“解决后无法更改配置策略 ':app:compile'”错误
问题描述
我目前正在尝试将 OpenId/Android-Apputh 迁移到 androidX 并在执行所有更改后遇到一个奇怪的问题 gradle 开始抛出以下错误:
> Cannot change strategy of configuration ':app:compile' after it has been resolved.
我添加后
android.enableJetifier=true
android.useAndroidX=true
到'gradle.properties'
暗示
我尝试记录所有可能的(使用println(cofigBlockName)
)配置块,发现sourceSets
在构建过程中没有调用 configBlock。所以可能是 Jetifier 将一些设置应用于sourceSets
.
有人知道如何解决吗?
android-common.gradle
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.compileSdkVersion
versionCode rootProject.versionNum
versionName rootProject.versionName
}
sourceSets {
main.manifest.srcFile 'AndroidManifest.xml'
main.java.srcDirs = ['java']
main.aidl.srcDirs = ['java']
main.res.srcDir 'res'
main.assets.srcDir 'assets'
main.resources.srcDir 'java'
test.setRoot('javatests');
test.java.srcDir('javatests');
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
warningsAsErrors true
disable 'InvalidPackage', 'TrulyRandom', 'UseCompoundDrawables', 'GradleDependency'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
// produces just the classes JAR
task jar(type: Copy, dependsOn:'bundleRelease') {
from("${project.buildDir}/intermediates/bundles/release/")
into("${project.buildDir}/libs/")
include('classes.jar')
rename('classes.jar', "appauth-${rootProject.versionName}.jar")
}
// produces a JAR containing sources
task sourcesJar(type: Jar, dependsOn:'generateReleaseSources') {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}
构建.gradle
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
apply from: '../config/android-common.gradle'
apply from: '../config/keystore.gradle'
android {
defaultConfig {
applicationId 'net.openid.appauthdemo'
project.archivesBaseName = 'appauth-demoapp'
vectorDrawables.useSupportLibrary = true
// Make sure this is consistent with the redirect URI used in res/raw/auth_config.json,
// or specify additional redirect URIs in AndroidManifest.xml
manifestPlaceholders = [
'appAuthRedirectScheme': 'com.lohika.android.test'
]
}
signingConfigs {
debugAndRelease {
storeFile file("${rootDir}/appauth.keystore")
storePassword "appauth"
keyAlias "appauth"
keyPassword "appauth"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
signingConfig signingConfigs.debugAndRelease
}
release {
signingConfig signingConfigs.debugAndRelease
}
}
}
project.ext.glideVersion = '4.7.1'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':library')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation "com.github.bumptech.glide:glide:${project.glideVersion}"
implementation 'com.squareup.okio:okio:1.14.1'
implementation 'joda-time:joda-time:2.10'
annotationProcessor "com.github.bumptech.glide:compiler:${project.glideVersion}"
}
apply from: '../config/style.gradle'
解决方案
我遇到了类似的问题。在我的情况下,注释处理器在 Java 9+ 上运行的 Java 语言级别存在问题,但 android 编译为 Java 8 或更低版本。所以添加 org.gradle.java.home 来构建选项有效:
./gradlew --info --scan --stacktrace --debug :app:clean :app:compileDebugSources -Dorg.gradle.java.home=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
希望这可以帮助
推荐阅读
- javascript - 我应该为哪种效果使用哪个 CSS3 过滤器属性
- java - 如何根据一个字段对数据列表进行分组
- php - 在 Laravel 中使用 sql 'like' 语句而不是多对一关系
- ios - IOS测试与Mac文件系统交互
- python-3.x - API请求后导出所有页面
- python - Python:根据列表更改字典中的值?
- javascript - 解析数组元素并分配给对象
- javascript - 在引导卡中获取新标签项时重新加载页面
- mysql - VBA 访问 - Form.Current 事件中的空记录集(错误 3021)
- postgresql - PostgreSQL 绝对相对 xpath 位置