Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Where are Gradle build tasks defined?

I am trying to learn about how a gradle build works. When I do a build, I see a bunch of tasks executed, e.g.:

app:assembleDebug
app:preBuild
app:packageDebug

I would like to see exactly what these tasks are doing. I assume these are Gradle / Groovy scripts. I tried unzipping all the jars under Android Studio. Lots of stuff there, but I don't see anything relevant (I may have missed something in the voluminous listing). Are these tasks hidden within a class file? Am I looking in the wrong place?

like image 673
DontPanic Avatar asked Jul 24 '18 14:07

DontPanic


People also ask

Where are Gradle tasks defined android studio?

gradle file, located in the root project directory, defines dependencies that apply to all modules in your project.

Where are Gradle tasks defined?

You define a Gradle task inside the Gradle build script. You can define the task pretty much anywhere in the build script. A task definition consists of the keyword task and then the name of the task, like this: task myTask. This line defines a task named myTask .

Where are Gradle tasks written?

We can define task types in the buildSrc folder which is located at the root project level. Gradle compiles everything that is inside and adds types to the classpath so our build script can use it.

Where is the build Gradle file in Android Studio?

gradle file is located inside your project folder under app/build. gradle.


1 Answers

All these tasks are created by the Gradle Android plugin, either the library version (com.android.library) or the application version (com.android.application). You can find the source code of these plugins in this repository.

However, it may be difficult to get insight on each task as some of them may be implemented by custom task types of the Android plugin, others may only be regular configured Gradle tasks. Also, the configuration of the tasks may be spreaded across multiple files, as many of them may be created dynamically.

But, in my opinion, it is unnecessary to know the exact functionality of each task, instead you should focus on the basic concepts of Android development and the Gradle plugin, e.g. build types and variants. The Android plugin provides a specific DSL and depending on the specified configuration, it will create the tasks automatically.

like image 149
Lukas Körfer Avatar answered Nov 05 '22 11:11

Lukas Körfer