启用androidX原因';无法更改配置的策略';:应用程序:编译';解决后';错误
我目前正在尝试将OpenId/Android Apputh迁移到androidX,在执行所有更改后,我遇到了一个奇怪的问题gradle开始抛出以下错误:启用androidX原因';无法更改配置的策略';:应用程序:编译';解决后';错误,android,android-gradle-plugin,androidx,Android,Android Gradle Plugin,Androidx,我目前正在尝试将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” 提示 我尝
> Cannot change strategy of configuration ':app:compile' after it has been resolved.
我加上
android.enableJetifier=true
android.useAndroidX=true
到“gradle.properties”
提示
我尝试记录所有可能的配置块(使用println(cofigBlockName)
),发现在构建过程中没有调用sourceset
configBlock。因此,Jetifier可能会将一些设置应用于sourceset
有人知道怎么解决吗
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"
}
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'
这项工作对我来说很好:
实现'com.google.android.exoplayer:exoplayer核心:2.10.2'
实现'com.google.android.exoplayer:exoplayer dash:2.10.2'
实现'com.google.android.exoplayer:exoplayer用户界面:2.9.6'
实现'com.google.android.exoplayer:exoplayer smoothstreaming:2.10.2'
我也面临类似的问题。在我的例子中,java语言级别存在问题,注释处理器在java 9+上运行,而android编译为java 8或更低版本。因此,将org.gradle.java.home添加到构建选项起到了作用:
./gradlew--info--scan--stacktrace--debug:app:clean:app:compiledBugSources-Dorg.gradle.java.home=/Applications/Android\Studio.app/Contents/jre/jdk/Contents/home
希望这有帮助我也在为同样的事情挣扎。。。正在寻找一个解决方案……您是否设法解决了这个问题?android stuido提供了迁移到androidX的选项。你试过了吗?这个问题最终解决了吗?