Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

See image below:

"Sync now" link to the left, Refresh icon button to the right

What exactly does the Sync now (blue) and refesh button (red) do respectively? What Gradle Tasks and/or other processes does Idea/Android Studio launche when clicking these?

I need to debug some errors with my gradle.build file and knowing what these buttons do will help me in that regard.

like image 378
Nilzor Avatar asked Jun 06 '14 11:06

Nilzor


1 Answers

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.

like image 146
Scott Barta Avatar answered Sep 29 '22 07:09

Scott Barta