[英]How to stop Android Studio from running my gradle task when syncing project with Gradle files?
When you make changes to the build configuration files in your project, Android Studio requires that you sync your project files so that it can import your build configuration changes and run some checks to make sure your configuration won't create build errors.
当您在项目中更改构建配置文件时,Android Studio要求您同步项目文件,以便它可以导入构建配置更改并运行一些检查以确保您的配置不会产生构建错误。
my build.gradle for app: 我的app.buildle.gradle
apply plugin: 'com.android.application'
android {
//... <--modified here
}
task myTask() {
println 'doing something...'
//time-consuming operations which may takes 16s or more
println 'done'
}
I just found that it runs myTask
every time I modified the build.gradle
for app, even if I didn't change it. 我刚刚发现,即使我没有更改,每次我修改app的
build.gradle
时,它都会运行myTask
。
Is that a normal operation when running some checks to make sure your configuration won't create build errors ? 运行某些检查以确保您的配置不会产生构建错误时,这是正常操作吗? If that is, how can I make the task not run when syncing?
如果是这样,如何使同步时任务不运行?
Environment : 环境 :
Android Studio 3.1.3 with gradle-4.9-bin.zip 带有gradle-4.9-bin.zip的Android Studio 3.1.3
Your task does not run at all, it is just configured. 您的任务根本不会运行,而只是配置了。
Gradle distinguishes between the configuration phase and the execution phase . Gradle区分配置阶段和执行阶段 。 On each invocation, every task is configured, but only the tasks passed to Gradle and their task dependencies are executed.
在每次调用时,都会配置每个任务,但是仅执行传递给Gradle的任务及其任务相关性。 As IntelliJ / AndroidStudio invokes Gradle on sync, every task is configured on sync.
当IntelliJ / AndroidStudio在同步时调用Gradle时,每个任务都将在同步时进行配置。 When you define a task in Gradle, the closure you pass is used for configuration.
在Gradle中定义任务时,您通过的闭包将用于配置。 Only task actions (internal functionality),
doFirst
and doLast
closures are executed during execution phase . 在执行阶段仅执行任务动作(内部功能),
doFirst
和doLast
关闭。 For your custom task, you should put your functionality into such a closure: 对于您的自定义任务,您应该将功能放入这样的闭包中:
task example {
println 'Configuration'
doLast {
println 'Execution'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.