This page describes how to build the Android Gradle plugin, and to test it.
Follow the instructions here to checkout the source code.
Once you have checked out the source code, the Gradle Plugin code can be found under tools/base
To edit the plugin import the Gradle project rooted in the tools
directory in to the most recent Intellij IDEA EAP.
You can run unit and integration tests directly from within Intellij IDEA. You can also run them with Gradle from the command line
tools/
To build AGP for use in other projects, use the “Execute Gradle Task” action to run :publishAndroidGradleLocal
(or :publishLocal
if you also need the databinding libraries)
The above command publishes the plugin to a local Maven repository located in ../out/repo/
, and it is also done as part of running the integration tests.
To debug unit tests simply use the debug action in Intellij IDEA.
To debug the Android Gradle Plugin being run from integration tests:
DEBUG_INNER_TEST=1
to the run configurationTo test your own Gradle projects, using your modified Android Gradle plugin, modify the settings.gradle
file to point to your local repository (where the above publishLocal target installed your build).
For example, if you ran the repo init command above in /my/aosp/work
, then the repository will be in /my/aosp/work/out/repo
.
You may need to change the version of the plugin as the version number used in the development branch is typically different from what was released. You can find the version number of the current build in tools/buildSrc/base/version.properties.
For example:
pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.1.0' } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } }
pluginManagement { repositories { maven { url '/my/aosp/work/out/repo' } gradlePluginPortal() google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.0-dev' } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url '/my/aosp/work/out/repo' } google() mavenCentral() } }
If your project does not have a pluginManagement
or dependencyResolutionManagement
block in settings.gradle
, look in build.gradle
for a buildscript
or allProjects
block, respectively, and make the changes there instead.
To debug a project like this simply run
$ ./gradlew --no-daemon -Dorg.gradle.debug=true someTask
and connect a remote debugger to port 5005
.
If you‘ve made changes, make sure you run the tests to ensure you haven’t broken anything:
cd base/build-system && ../../gradlew test
Presubmit runs all the tests, so another strategy is to guess which tests may be affected by your change and run them locally but rely on the presubmit tests to run all the integration tests.