This page describes how to build the Android Gradle plugin, and to test it.
Follow the instructions here to get checkout the source code.
Once you have checked out the source code, the Gradle Plugin code can be found under tools/base.git
All of the projects are build together in a multi-module Gradle project setup. The root of that project is tools/
The Gradle Plugin is currently built with Gradle 2.2. To ensure you are using the right version, please use the gradle wrapper scripts (
To prepare the build environment:
This will populate a local repo with dependencies that are normally found in MavenCentral.
This will also copy your global gradle.properties (~/.gradle/gradle.properties) in the out/ folder since we redirect ~/.gradle to out/.gradle.
Finally you can build the Gradle plugin (and associated libraries) with
If assemble fails the first time you execute it, try the following
To test the plugin, you need to
If your tests fail because it cannot find all the necessary dependencies, execute publishLocal first (see below.)
Additionally, you should connect a device to your workstation and run:
To run a specific connectedIntegrationTest, run:
The code of the plugin and its dependencies is located in tools/base. You can open this project with IntelliJ as there is already a tools/base/.idea setup.
tools/base/build-system/integration-test/sample contain a number of sample projects and tests for the plugin. To run the integration tests. run:
To run just a single test, you can use the --tests argument with the test class you want to run. e.g.:
To compile the samples manually, publish the plugin and its libraries first with
(Tip: you can use camelcase prefixes for target names, so for the above you can just run
Then set the CUSTOM_REPO environment variable to the repository in the "
(Also, running check, :base:integration-test:test, and connectedIntegrationTest does publishLocal first).
For debugging unit tests, you can use the following:
$ ./gradlew :base:gradle:test --debug-jvm --tests='*.BasicTest'
For debugging integration tests code (not the Gradle code being executed as part of the test):
For debugging plugin code when run locally:
$ cd a-sample-project # Make sure build.gradle points at your local repo, as described below.
$ ./gradlew --no-daemon -Dorg.gradle.debug=true someTask
If you need to debug an integration test while running within the integration tests framework, you can do :
$ DEBUG_INNER_TEST=1 ./gradlew :b:int:test -D:base:integration-test:test.single=ShrinkTest # to run and debug only one test. --tests should also work.
This will silently wait for you to connect a debugger on port 5006. You can combine this with
Using locally built plugin
To test your own Gradle projects, using your modified Android Gradle plugin, modify the build.gradle file to point to your local repository (where the above publishLocal target installed your build).
In other words, assuming your
You need to point to your own repository instead. For example, if you ran the repo init command above in
If you've made changes, make sure you run the tests to ensure you haven't broken anything:
The tests requires a number of packages in the SDK. To run all tests:
- Install the android SDK from here: https://developer.android.com/sdk/index.html#Other
- Execute tools/android
- Click Deselect all and check Obsolete (at the bottom)
- Select (not including the italic headings)…
Android SDK Build-tools 22.0.1
Android SDK Build-tools 21.1.2
Android SDK Build-tools (Obselete) 21.1.1
Android SDK Build-tools (Obselete) 21.1
Android SDK Build-tools (Obselete) 21
Android SDK Build-tools (Obselete) 20
Android SDK Build-tools 19.1
Android 5.1.1 (API 22)
SDK Platform 22
Android 5.0.1 (API 21)
SDK Platform 21
Android 4.4.2 (API 19)
SDK Platform 19
Android 4.0.3 (API 15)
SDK Platform 15
Android Support Repository 12
Android Support Library 22
Google Play Services 23Google Repository 16
Alternatively, you can execute this command to install the needed dependencies automatically:
$ android update sdk -u -a -t build-tools-22.0.1,build-tools-21.1.2,build-tools-21.1.1,build-tools-21.1.0,build-tools-21.0.0,build-tools-19.1.0,android-22,android-21,android-19,android-15,extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository,build-tools-25.0.0
Build Overview >