Android项目中的Gradle任务顺序

时间:2017-10-29 23:44:37

标签: android gradle android-gradle

我的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

如何在构建完成后执行clearInterval()

1 个答案:

答案 0 :(得分:1)

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

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

gradle:

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 =>释放
  • ./gradlew release:archiveRelease =>释放

gradle:

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

build.finalizedBy release
release.dependsOn archiveRelease