英文:
Cannot run Project.afterEvaluate(Action) when the project is already evaluated
问题
以下是您提供的内容的翻译部分:
项目类型:Android
Gradle包装程序:gradle-7.5
Gradle插件:7.4.2
应用程序模块build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}
android {
...
defaultConfig {
...
}
flavorDimensions 'app', 'channel'
productFlavors {
dev {
dimension 'app'
applicationIdSuffix '.dev'
}
product {
dimension 'app'
}
google {
dimension 'channel'
}
android.applicationVariants.all { variant ->
def dirPath = project.projectDir.absolutePath + '/build/outputs/apk/' + dirName + '/'
def filePath = ''
variant.outputs.all {
outputFileName = "xxx.apk"
filePath = outputFileName
}
variant.getAssembleProvider().get().doLast {
if (variant.buildType.name == 'release') {
def cmd = 'cd .. && ./ossutilmac64 cp -f ' + dirPath + filePath + ' oss://android-test-sz/' + filePath
exec {
ExecSpec execSpec ->
executable 'zsh'
args '-c', cmd
standardOutput = out
}
println(out.toString())
}
}
}
}
}
dependencies {
...
}
当我运行Shell命令“./gradlew assembleDevGoogleRelease”来构建APK并使用Gradle 7上传APK到OSS时,不幸的是,构建失败了(在Gradle 6.x中是正常的)。
> Task :app:assembleDevGoogleRelease FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '...app/build.gradle' line: 222
* What went wrong:
Execution failed for task ':app:assembleDevGoogleRelease'.
> Cannot run Project.afterEvaluate(Action) when the project is already evaluated.
错误发生在第222行的“exec {”中。
非常感谢您的帮助。提前感谢。 :slight_smile:
英文:
Project type: Android
Gradle wrapper: gradle-7.5
Gradle plugin: 7.4.2
app module build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id "org.jetbrains.kotlin.kapt"
}
android {
...
defaultConfig {
...
}
flavorDimensions "app", "channel"
productFlavors {
dev {
dimension "app"
applicationIdSuffix ".dev"
}
product {
dimension "app"
}
google {
dimension "channel"
}
android.applicationVariants.all { variant ->
def dirPath = project.projectDir.absolutePath + '/build/outputs/apk/' + dirName + '/'
def filePath = ''
variant.outputs.all {
outputFileName = "xxx.apk"
filePath = outputFileName
}
variant.getAssembleProvider().get().doLast {
if (variant.buildType.name == 'release') {
def cmd = 'cd .. && ./ossutilmac64 cp -f ' + dirPath + filePath + ' oss://android-test-sz/' + filePath
exec {
ExecSpec execSpec ->
executable 'zsh'
args '-c', cmd
standardOutput = out
}
println(out.toString())
}
}
}
}
}
dependencies {
...
}
when I run shell “./gradlew assembleDevGoogleRelease” to build apk and upload apk to oss with Gradle 7, unfortunately, the build fails. (Gradle 6.x is ok)
> Task :app:assembleDevGoogleRelease FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '...app/build.gradle' line: 222
* What went wrong:
Execution failed for task ':app:assembleDevGoogleRelease'.
> Cannot run Project.afterEvaluate(Action) when the project is already evaluated.
The error line 222 is the “exec {” in doLast.
Any help is much appreciated. Thanks in advance. :slight_smile:
答案1
得分: 1
你应该将"android.applicationVariants.all"放在外部块中。
英文:
You should place the applicationVariants.all on the outside block
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}
android {
// ...
defaultConfig {
// ...
}
flavorDimensions 'app', 'channel'
productFlavors {
dev {
dimension 'app'
applicationIdSuffix '.dev'
}
product {
dimension 'app'
}
google {
dimension 'channel'
}
}
}
android.applicationVariants.all { variant ->
def dirPath = project.projectDir.absolutePath + '/build/outputs/apk/' + dirName + '/'
def filePath = ''
variant.outputs.all {
outputFileName = "xxx.apk"
filePath = outputFileName
}
variant.getAssembleProvider().get().doLast {
if (variant.buildType.name == 'release') {
def cmd = 'cd .. && ./ossutilmac64 cp -f ' + dirPath + filePath + ' oss://android-test-sz/' + filePath
exec {
executable 'zsh'
args '-c', cmd
standardOutput = out
}
println(out.toString())
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论