Android plugin 3.0.0-alpha1 and higher include the following updates
that help address bugs and performance issues of large Android projects:
- Better parallelism for multi-module projects through fine grained task graph.
- Variant aware dependency management.
- Compilation avoidance:
- Automatic detection of implementation-only changes (a feature of Gradle since version 3.4).
- New
api,implementation,compileOnlyandruntimeOnlyconfigurations allow libraries to not always leak their dependencies to their consumers.
- Incremental dexing. Dex’ing is now done at a per class level. This allows for more incrementality and will result in faster incremental builds. You should also expect improved build speeds for applications using legacy multi-dex (minSdkVersion < 21).
- Improved incremental resource processing with AAPT2. To enable AAPT2, add
the following to your
gradle.propertiesfile:android.enableAapt2=true - Built-in support for Java 8 libraries and certain Java 8 language features. Jack is no longer required, and you should first disable Jack to use the improved Java 8 support built into the default toolchain. For more information see how to use Java 8 language features.
- Android Test Utility. You can now install
another test helper APK before your instrumentation tests are run. This makes
it easier to use popular testing tools like Test Butler. To have the helper
APK installed before your instrumentation tests are run, use the
androidTestUtilkeyword, as shown in the following example:dependencies { androidTestUtil 'com.linkedin.testbutler:test-butler-app:1.3.0@apk' ... } - Support for the Android O Developer Preview.
In order to bring about these improvements, there are some breaking changes in the plugin behavior, DSL, and APIs. These breaking changes impact both build files and Gradle plugins. There may also be more breaking changes before the stable release of the plugin, so you should keep checking this page.
For instructions on how to migrate your own project to use this plugin, go to Migrate to the new plugin.
What to expect from performance
The main focus of this version is to address the build performance issues of Android projects with a large number of modules. When using the new plugin with these projects, you should experience the following:
- Faster configuration time (the times it take to configure all the gradle projects) due to delayed dependency resolution.
- Dependency resolution only for the projects and variants you are building.
- Simple changes to code or resources should result in faster incremental build times, especially for changes in modules deep in the dependency graph of an app.
This is a first step, with a strong focus on improving scalability and parallelism, and on improving tasks to be more incremental. You can expect more changes in later preview releases and down the line after the first stable release.
On a test skeleton project with ~130 modules and a large number of external dependencies, but no code/resources, we are seeing the following performance improvements:
| Android plugin version + Gradle version | Android plugin 2.2.0 + Gradle 2.14.1 | Android plugin 2.3 RC1 + Gradle 3.3 | Android plugin 3.0 preview + Gradle 4.0-milestone-1 |
|---|---|---|---|
Configuration (e.g. running help) |
~2 mins | ~9 s | ~2.5 s |
| 1-line Java change (implementation change) | ~2 mins 15 s | ~29 s | ~6.4 s |
To try the new plugin on your own projects. If you see less of a performance improvement than you expected, we are looking for feedback with build profiling. Please consider using the Gradle Profiler to provide us with more data. File a bug and include a Chrome trace of your build using the Gradle Profiler.
Known issues
- Generating multi-apks using the
splits {}block doesn’t work; use the latest stable version of the plugin instead. - While using this plugin with Android Studio, dependencies on local AAR files are not yet supported.
- Does not currently work with the Protobuf plugin.
- Does not currently work with the Retrolambda plugin. However, you should instead use the plugin's built-in support for Java 8 language features.
- This plugin breaks the third party android-apt plugin. Switch to the built-in annotation processor support which has been improved to handle resolving dependencies lazily.