Gradle
What is Gradle?
Gradle is a graph of tasks. For example, compile, run tests, build an APK. The description is in build.gradle or build.gradle.kts. The first is the Groovy DSL. The second is the Kotlin DSL. The gradlew script that comes with the project keeps everyone on the same Gradle version.
What is Gradle used for?
Behind an Android Studio button there is usually a Gradle task.
- Downloading a library dependency
- Building a debug and a release package
- Running tests
- Keeping the version number in one place
What can you do with Gradle?
With Gradle you bind a repeated build command to one task. On Android the variant, the signature, and ProGuard also pass through here. It does not write the app’s screen. It only builds and checks.
Is Gradle hard to learn?
A small file is readable. The difficulty is the plugin version, the cache, and the length of the error text. Always giving the command through gradlew reduces a version fight with a global gradle.
Advantages and limits
Advantage: it is Android’s official build path, and an incremental build saves time. Limit: the first download is heavy, and an old plugin may not agree with a new JDK. Maven still stands in a Java project that wants simpler XML.
Basic ideas
A plugin adds a capability. For example, the Android plugin. A dependency is declared with implementation. The cache is there so the same work is not repeated.
- ./gradlew runs the project’s own Gradle
- settings.gradle lists the modules
- build stores the finished output
- A task adds your own command
A short example
This command shows which tasks exist in the project. On Windows the command may be gradlew.bat tasks.
./gradlew tasks
Common questions
- Is Gradle a language? No. It is a build tool. The description can be Groovy or Kotlin.
- What is gradlew for? So every developer runs the same version.
- Does Android build without Gradle? Not on the ordinary path. Studio calls Gradle too.