gpt4 book ai didi

android - Android项目中的Gradle任务顺序

转载 作者:行者123 更新时间:2023-11-29 01:06:11 25 4
gpt4 key购买 nike

我的 Android 项目中依赖任务的顺序有问题。

这是我的 app/build.gradle 文件的一部分:

task release

task archiveRelease(type: Copy) {
println 'copy apk and mapping files'
from './build/outputs/'
into "../releases/${rootProject.ext.configuration.version_code}_${rootProject.ext.configuration.version_name}"
include('apk/release/app-release.apk', 'mapping/release/mapping.txt')
rename('app-release.apk', "${rootProject.ext.configuration.package}_${rootProject.ext.configuration.version_code}_${rootProject.ext.configuration.version_name}.apk")
rename('mapping.txt', "mapping_${rootProject.ext.configuration.version_code}_${rootProject.ext.configuration.version_name}.txt")
}

project.afterEvaluate {

dependencyUpdates.dependsOn clean
assembleRelease.dependsOn clean

archiveRelease.mustRunAfter("assembleRelease")
release.dependsOn assembleRelease
}

但是当我启动 release 任务时,它会在开头打印 copy apk and mapping files 而不是在 assembleRelease 的结尾。这是控制台输出:

$ ./gradlew release
Parallel execution with configuration on demand is an incubating feature.

> Configure project :app
copy apk and mapping files

如何在构建完成后执行archiveRelease

最佳答案

如果你想在使用以下调用发布任务时触发构建:

  • ./gradlew release : build => archiveRelease => release
  • ./gradlew build : build => archiveRelease => release

渐变:

task(release) {
doLast {
println 'release task'
}
}
task(archiveRelease) {
doLast {
println 'archiveRelease task'
}
}

build.finalizedBy release
archiveRelease.dependsOn build
release.dependsOn archiveRelease

所以在那种情况下,./gradlew build./gradlew release 是等价的,如果那是你想要的。

但是如果你想要一个独立的release任务来执行

  • ./gradlew build : build => archiveRelease => release
  • ./gradlew release : archiveRelease => 发布

渐变:

task(release) {
doLast {
println 'release task'
}
}
task(archiveRelease) {
doLast {
println 'archiveRelease task'
}
}

build.finalizedBy release
release.dependsOn archiveRelease

关于android - Android项目中的Gradle任务顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47006416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com