为什么我不能在preReleaseBuild任务上设置任务依赖,但preBuild任务有效?

时间:2015-08-18 22:18:08

标签: android gradle android-gradle

如何设置对这两个任务的依赖? preReleaseBuildpreDebugBuild

我想做以下事情:

preReleaseBuild.dependsOn switchToRelease
preDebugBuild.dependsOn switchToDebug

但是我收到了这个错误:

Error:(251, 0) Could not find property 'preReleaseBuild' on project ':app'.

这两项任务显然存在,因为我在运行gradle assembleRelease

时会看到它们
Zaks-MBP:androidapp zak$ gradle assembleRelease
Parallel execution is an incubating feature.
:analytics:compileJava
:app:gce2retrofit-release
:feed:compileJava
:gcm:compileJava
:backend:processResources UP-TO-DATE
:app:gce2retrofit-release UP-TO-DATE
:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:checkReleaseManifest
:app:preDebugBuild UP-TO-DATE

1 个答案:

答案 0 :(得分:0)

需要使用afterEvaluate

afterEvaluate {
    preReleaseBuild.dependsOn switchToRelease
    preDebugBuild.dependsOn switchToDebug
}