What Gradle task(s) does IDEA / Android Studio run when I press Sync Now and the Refresh button?

对着背影说爱祢 提交于 2019-11-30 17:52:56

Both those actions do essentially the same thing. Their primary task is to evaluate the Gradle build files to synchronize Android Studio's picture of the structure of the project with the source of truth in the Gradle build files. It doesn't execute a specific task to do this, but it instead evaluates the build file, executing it up to the point before it would actually fire off any tasks. Gradle builds up an internal model of the state of the project, and it hands this model off to Android Studio, which then updates its notion of project structure to reflect any changes.

After this model evaluation process, which again doesn't invoke any specific tasks, Android Studio does execute the generateSources task. This step creates any automatically generated source files, such as R.java, which need to be there for the IDE to provide proper syntax highlighting and content assist for doing normal development.

The fact that Android Studio will execute the build file at times other than doing an actual build is a reason why you have to be careful about knowing the execution context of any custom code you put in the build file, especially if that code does long-running or potentially destructive operations -- that code could be run at times you may not expect, more often than you expect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!