The Android Studio build system is based on Gradle, and the Android Gradle plugin adds several features that are specific to building Android apps. Although the Android plugin is typically updated in lock-step with Android Studio, the plugin (and the rest of the Gradle system) can run independent of Android Studio and be updated separately.
This page explains how to keep your Gradle tools up to date and what's in the recent updates.
For details about how to configure your Android builds with Gradle, see the following pages:
For more information about the Gradle build system, see the Gradle user guide.
Update the Android Gradle plugin
When you update Android Studio, you may receive a prompt to automatically update the Android Gradle plugin to the latest available version. You can choose to accept the update or manually specify a version based on your project's build requirements.
You can specify the plugin version in
either the File > Project
Structure > Project menu in Android Studio, or
the top-level build.gradle
file. The plugin version applies to
all modules built in that Android Studio project. The following example sets
the plugin to version 3.5.2 from the
build.gradle
file:
buildscript { repositories { // Gradle 4.1 and higher include support for Google's Maven repo using // the google() method. And you need to include this repo to download // Android Gradle plugin 3.0.0 or higher. google() ... } dependencies { classpath 'com.android.tools.build:gradle:3.5.2' } }
Caution: You should not use dynamic dependencies in version
numbers, such as 'com.android.tools.build:gradle:2.+'
. Using
this feature can cause unexpected version updates and difficulty resolving
version differences.
If the specified plugin version has not been downloaded, Gradle downloads it the next time you build your project or click Tools > Android > Sync Project with Gradle Files from the Android Studio menu bar.
Update Gradle
When you update Android Studio, you may receive a prompt to also update Gradle to the latest available version. You can choose to accept the update or manually specify a version based on your project's build requirements.
The following table lists which version of Gradle is required for each version of the Android Gradle plugin. For the best performance, you should use the latest possible version of both Gradle and the plugin.
Plugin version | Required Gradle version |
---|---|
1.0.0 - 1.1.3 | 2.2.1 - 2.3 |
1.2.0 - 1.3.1 | 2.2.1 - 2.9 |
1.5.0 | 2.2.1 - 2.13 |
2.0.0 - 2.1.2 | 2.10 - 2.13 |
2.1.3 - 2.2.3 | 2.14.1+ |
2.3.0+ | 3.3+ |
3.0.0+ | 4.1+ |
3.1.0+ | 4.4+ |
3.2.0 - 3.2.1 | 4.6+ |
3.3.0 - 3.3.2 | 4.10.1+ |
3.4.0 - 3.4.1 | 5.1.1+ |
3.5.0+ | 5.4.1-5.6.4 |
You can specify the Gradle version in either the File >
Project Structure > Project menu in
Android Studio, or by editing the Gradle distribution reference in the
gradle/wrapper/gradle-wrapper.properties
file. The following
example sets the Gradle version to 5.4.1 in the
gradle-wrapper.properties
file.
... distributionUrl = https\://services.gradle.org/distributions/gradle-5.4.1-all.zip ...
3.5.0 (August 2019)
Android Gradle plugin 3.5.0, along with Android Studio 3.5, is a major release and a result of Project Marble, which is a focus on improving three main areas of the Android developer tools: system health, feature polish, and fixing bugs. Notably, improving project build speed was a main focus for this update.
For information about these and other Project Marble updates, read the Android Developers blog post or the sections below.
This version of the Android plugin requires the following:
Gradle 5.4.1 or higher. To learn more, read the section about updating Gradle.
SDK Build Tools 28.0.3 or higher.
3.5.1 (October 2019)
This minor update supports Android Studio 3.5.1 and includes various bug fixes and performance improvements. To see a list of noteable bug fixes, read the related post on the Release Updates blog.
3.5.2 (November 2019)
This minor update supports Android Studio 3.5.2 and includes various bug fixes and performance improvements. To see a list of noteable bug fixes, read the related post on the Release Updates blog.
Incremental annotation processing
The Data Binding annotation
processor supports incremental annotation
processing
if you set android.databinding.incremental=true
in your gradle.properties
file. This optimization results in improved
incremental build performance. For a full list of optimized annotation
processors, refer to the table of incremental annotation
processors.
Additionally, KAPT 1.3.30 and higher also support incremental annotation
processors, which you can enable by including kapt.incremental.apt=true
in
your gradle.properties
file.
Cacheable unit tests
When you enable unit tests to use Android resources, assets, and manifests by
setting includeAndroidResources
to true
, the Android Gradle plugin generates a test config file
containing absolute paths, which breaks cache relocatability. You can instruct
the plugin to instead generate the test config using relative paths, which
allows the AndroidUnitTest
task to be fully cacheable, by including the
following in your gradle.properties
file:
android.testConfig.useRelativePath = true
Known issues
When using Kotlin Gradle plugin 1.3.31 or earlier, you might see the following warning when building or syncing your project:
WARNING: API 'variant.getPackageLibrary()' is obsolete and has been replaced with 'variant.getPackageLibraryProvider()'.
To resolve this issue, upgrade the plugin to version 1.3.40 or higher.
3.4.0 (April 2019)
This version of the Android plugin requires the following:
Gradle 5.1.1 or higher. To learn more, read the section about updating Gradle.
SDK Build Tools 28.0.3 or higher.
3.4.2 (July 2019)
This minor update supports Android Studio 3.4.2 and includes various bug fixes and performance improvements. To see a list of noteable bug fixes, read the related post on the Release Updates blog.
3.4.1 (May 2019)
This minor update supports Android Studio 3.4.1 and includes various bug fixes and performance improvements. To see a list of noteable bug fixes, read the related post on the Release Updates blog.
New features
New lint check dependency configurations: The behavior of
lintChecks
has changed and a new dependency configuration,lintPublish
, has been introduced to give you more control over which lint checks are packaged in your Android libraries.lintChecks
: This is an existing configuration that you should use for lint checks you want to only run when building your project locally. If you were previously using thelintChecks
dependency configuration to include lint checks in the published AAR, you need to migrate those dependencies to instead use the newlintPublish
configuration described below.lintPublish
: Use this new configuration in library projects for lint checks you want to include in the published AAR, as shown below. This means that projects that consume your library also apply those lint checks.
The following code sample uses both dependency configurations in a local Android library project.
dependencies { // Executes lint checks from the ':lint' project at build time. lintChecks project(':lint') // Packages lint checks from the ':lintpublish' in the published AAR. lintPublish project(':lintpublish') }
In general, packaging and signing tasks should see an overall build speed improvement. If you notice a performance regression related to these tasks, please report a bug.
Behavior changes
Android Instant Apps Feature plugin deprecation warning: If you’re still using the
com.android.feature
plugin to build your instant app, Android Gradle plugin 3.4.0 will give throw you a deprecation warning. To make sure you can still build you instant app on future versions of the plugin, migrate your instant app to using the dynamic feature plugin, which also allows you to publish both your installed and instant app experiences from a single Android App Bundle.R8 enabled by default: R8 integrates desugaring, shrinking, obfuscating, optimizing, and dexing all in one step—resulting in noticeable build performance improvements. R8 was introduced in Android Gradle plugin 3.3.0 and is now enabled by default for both app and Android library projects using plugin 3.4.0 and higher.
The image below provides a high-level overview of the compile process before R8 was introduced.
Now, with R8, desugaring, shrinking, obfuscating, optimizing, and dexing (D8) are all completed in one step, as illustrated below.
Keep in mind, R8 is designed to work with your existing ProGuard rules, so you’ll likely not need to take any actions to benefit from R8. However, because it’s a different technology to ProGuard that’s designed specifically for Android projects, shrinking and optimization may result in removing code that ProGuard may have not. So, in this unlikely situation, you might need to add additional rules to keep that code in your build output.
If you experience issues using R8, read the R8 compatibility FAQ to check if there’s a solution to your issue. If a solution isn’t documented, please report a bug. You can disable R8 by adding one of the following lines to your project’s
gradle.properties
file:# Disables R8 for Android Library modules only. android.enableR8.libraries = false # Disables R8 for all modules. android.enableR8 = false
ndkCompile
is deprecated: You now get a build error if you try to usendkBuild
to compile your native libraries. You should instead use either CMake or ndk-build to Add C and C++ code to your project.
Known issues
The correct usage of unique package names are currently not enforced but will become more strict on later versions of the plugin. On Android Gradle plugin version 3.4.0, you can opt-in to check whether your project declares acceptable package names by adding the line below to your
gradle.properties
file.android.uniquePackageNames = true
To learn more about setting a package name through the Android Gradle plugin, see Set the application ID.
3.3.0 (January 2019)
This version of the Android plugin requires the following:
Gradle 4.10.1 or higher. To learn more, read the section about updating Gradle.
SDK Build Tools 28.0.3 or higher.
3.3.2 (March 2019)
This minor update supports Android Studio 3.3.2 and includes various bug fixes and performance improvements. To see a list of noteable bug fixes, read the related post on the Release Updates blog.
3.3.1 (February 2019)
This minor update supports Android Studio 3.3.1 and includes various bug fixes and performance improvements.
New features
Improved classpath synchronization: When resolving dependencies on your runtime and compile time classpaths, the Android Gradle plugin attempts to fix certain downstream version conflicts for dependencies that appear across multiple classpaths.
For example, if the runtime classpath includes Library A version 2.0 and the compile classpath includes Library A version 1.0, the plugin automatically updates the dependency on the compile classpath to Library A version 2.0 to avoid errors.
However, if the runtime classpath includes Library A version 1.0 and the compile includes Library A version 2.0, the plugin does not downgrade the dependency on the compile classpath to Library A version 1.0, and you will get an error. To learn more, see Fix conflicts between classpaths.
Improved incremental Java compilation when using annotation processors: This update decreases build time by improving support for incremental Java compilation when using annotation processors.
- For projects using Kapt (most Kotlin-only projects and Kotlin-Java hybrid projects): Incremental Java compilation is enabled, even when you use data binding or the retro-lambda plugin. Annotation processing by the Kapt task is not yet incremental.
For projects not using Kapt (Java-only projects): If the annotation processors you use all support incremental annotation processing, incremental Java compilation is enabled by default. To monitor incremental annotation processor adoption, watch Gradle issue 5277.
If, however, one or more annotation processors do not support incremental builds, incremental Java compilation is not enabled. Instead, you can include the following flag in your
gradle.properties
file:android.enableSeparateAnnotationProcessing=true
When you include this flag, the Android Gradle plugin executes the annotation processors in a separate task and allows the Java compilation task to run incrementally.
Better debug info when using obsolete API: When the plugin detects that you're using an API that's no longer supported, it can now provide more-detailed information to help you determine where that API is being used. To see the additional info, you need to include the following in your project's
gradle.properties
file:android.debug.obsoleteApi=true
You can also enable the flag by passing
-Pandroid.debug.obsoleteApi=true
from the command line.You can run instrumentation tests on dynamic feature modules from the command line.
Behavior changes
Lazy task configuration: The plugin now uses Gradle’s new task creation API to avoid initializing and configuring tasks that are not required to complete the current build (or tasks not on the execution task graph). For example, if you have multiple build variants, such as “release” and “debug” build variants, and you're building the “debug” version of your app, the plugin avoids initializing and configuring tasks for the “release” version of your app.
Calling certain older methods in the Variants API, such as
variant.getJavaCompile()
, might still force task configuration. To make sure that your build is optimized for lazy task configuration, invoke new methods that instead return aTaskProvider
object, such asvariant.getJavaCompileProvider()
.If you execute custom build tasks, learn how to adapt to Gradle’s new task-creation API.
For a given build type, when setting
useProguard false
, the plugin now uses R8 instead of ProGuard to shrink and obfuscate your app’s code and resources. To learn more about R8, read this blog post from the Android Developer’s Blog.Faster R class generation for library projects: Previously, the Android Gradle plugin would generate an
R.java
file for each of your project's dependencies and then compile those R classes alongside your app's other classes. The plugin now generates a JAR containing your app's compiled R class directly, without first building intermediateR.java
classes. This optimization may significantly improve build performance for projects that include many library subprojects and dependencies, and improve the indexing speed in Android Studio.When building an Android App Bundle, APKs generated from that app bundle that target Android 6.0 (API level 23) or higher now include uncompressed versions of your native libraries by default. This optimization avoids the need for the device to make a copy of the library and thus reduces the on-disk size of your app. If you'd rather disable this optimization, add the following to your
gradle.properties
file:android.bundle.enableUncompressedNativeLibs = false
The plugin enforces minimum versions of some third-party plugins.
Single-variant project sync: Syncing your project with your build configuration is an important step in letting Android Studio understand how your project is structured. However, this process can be time-consuming for large projects. If your project uses multiple build variants, you can now optimize project syncs by limiting them to only the variant you have currently selected.
You need to use Android Studio 3.3 or higher with Android Gradle Plugin 3.3.0 or higher to enable this optimization. When you meet these requirements, the IDE prompts you to enable this optimization when you sync your project. The optimization is also enabled by default on new projects.
To enable this optimization manually, click File > Settings > Experimental > Gradle (Android Studio > Preferences > Experimental > Gradle on a Mac) and select the Only sync the active variant checkbox.
Note: This optimization fully supports projects that include Java and C++ languages, and has some support for Kotlin. When enabling the optimization for projects with Kotlin content, Gradle sync falls back to using full variants internally.
Automatic downloading of missing SDK packages: This functionality has been expanded to support NDK. To learn more, read Auto-download missing packages with Gradle.
Bug Fixes
Android Gradle plugin 3.3.0 fixes the following issues:
- The build process calling
android.support.v8.renderscript.RenderScript
instead of the AndroidX version, despite Jetifier being enabled - Clashes due to
androidx-rs.jar
including statically bundledannotation.AnyRes
- When using RenderScript, you no longer have to manually set the Build Tools
version in your
build.gradle
files
- The build process calling
3.2.0 (September 2018)
This version of the Android plugin requires the following:
- Gradle 4.6 or higher. To learn more, read the section about updating Gradle.
- SDK Build Tools 28.0.3 or higher.
3.2.1 (October 2018)
With this update, you no longer need to specify a version for the SDK Build Tools. The Android Gradle plugin now uses version 28.0.3 by default.
New features
Support for building Android App Bundles: The app bundle is a new upload format that includes all your app’s compiled code and resources while deferring APK generation and signing to the Google Play Store. You no longer have to build, sign, and manage multiple APKs, and users get smaller downloads that are optimized for their device. To learn more, read About Android App Bundles.
Support for improved incremental build speeds when using annotation processors: The
AnnotationProcessorOptions
DSL now extendsCommandLineArgumentProvider
, which enables either you or the annotation processor author to annotate arguments for the processor using incremental build property type annotations. Using these annotations improves the correctness and performance of incremental and cached clean builds. To learn more, read Pass arguments to annotation processors.Migration tool for AndroidX: When using Android Gradle plugin 3.2.0 with Android 3.2 and higher, you can migrate your project’s local and Maven dependencies to use the new AndroidX libraries by selecting Refactor > Migrate to AndroidX from the menu bar. Using this migration tool also sets the following flags to
true
in yourgradle.properties
file:android.useAndroidX
: When set totrue
, the Android plugin uses the appropriate AndroidX library instead of a Support Library. When this flag is not specified, the plugin sets it tofalse
by default.android.enableJetifier
: When set totrue
, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. When this flag is not specified, the plugin sets it tofalse
by default. You can set this flag totrue
only whileandroid.useAndroidX
is also set totrue
, otherwise you get a build error.
To learn more, read the AndroidX overview.
New code shrinker, R8: R8 is a new tool for code shrinking and obfuscation that replaces ProGuard. You can start using the preview version of R8 by including the following in your project’s
gradle.properties
file:android.enableR8 = true
Behavior changes
- Desugaring with D8 is now enabled by default.
AAPT2 is now on Google's Maven repo. To use AAPT2, make sure that you have the
google()
dependency in yourbuild.gradle
file, as shown below:buildscript { repositories { google() // here jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.0' } } allprojects { repositories { google() // and here jcenter() }
Native multidex is now enabled by default. Previous versions of Android Studio enabled native multidex when deploying the debug version of an app to a device running Android API level 21 or higher. Now, whether you’re deploying to a device or building an APK for release, the Android Gradle plugin enables native multidex for all modules that set
minSdkVersion=21
or higher.The plugin now enforces a minimum version of the protobuf plugin (0.8.6), Kotlin plugin (1.2.50), and Crashlytics plugin (1.25.4).
The feature module plugin,
com.android.feature
, now enforces the use of only letters, digits, and underscores when specifying a module name. For example, if your feature module name includes dashes, you get a build error. This behavior matches that of the dynamic feature module plugin.
Bug fixes
- JavaCompile is now cacheable in projects with data binding. (Issue #69243050)
- Better compile avoidance for library modules with data binding. (Issue #77539932)
- You can now re-enable configure-on-demand if you've disable it in earlier versions due to some unpredictable build errors. (Issue #77910727)
3.1.0 (March 2018)
This version of the Android plugin requires the following:
- Gradle 4.4 or higher. To learn more, read the section about updating Gradle.
- Build Tools 27.0.3 or higher.
Keep in mind, you no longer need to specify a version for the build
tools using the
android.buildToolsVersion
property—the plugin uses the minimum required version by default.
New DEX compiler, D8
By default, Android Studio now uses a new DEX
compiler called D8. DEX compilation is the process of transforming .class
bytecode into .dex
bytecode for the Android Runtime (or Dalvik, for older
versions of Android). Compared to the previous compiler, called DX, D8
compiles faster and outputs smaller DEX files, all while having the same or
better app runtime performance.
D8 shouldn't change your day-to-day app development workflow. However, if you
experience any issues related to the new compiler, please
report a bug. You can temporarily disable D8 and
use DX by including the following in your project's gradle.properties
file:
android.enableD8=false
For projects that
use Java 8 language features,
incremental desugaring is enabled by default. You can disable it by
specifying the following in your project's gradle.properties
file:
android.enableIncrementalDesugaring=false.
Preview users: If you're already using a preview version of D8, note that it now compiles against libraries included in the SDK build tools—not the JDK. So, if you are accessing APIs that exist in the JDK but not in the SDK build tools libraries, you get a compile error.
Behavior changes
When building multiple APKs that each target a different ABI, the plugin no longer generates APKs for the following ABIs by default:
mips
,mips64
, andarmeabi
.If you want to build APKs that target these ABIs, you must use NDK r16b or lower and specify the ABIs in your
build.gradle
file, as shown below:splits { abi { include 'armeabi', 'mips', 'mips64' ... } }
When building configuration APKs for an Android Instant App, language configuration splits are now grouped by the root language by default. For example, if your app includes resources for
zh-TW
orzh-CN
locales, Gradle will package those resources in azh
language configuration split. You can override this behavior by defining your own groups using theinclude
property, as shown below:splits { language { enable true // Each string defines a group of locales that // Gradle should package together. include "in,id", "iw,he", "fil,tl,tgl", "yue,zh,zh-TW,zh-CN" } }
The Android plugin's build cache now evicts cache entries that are older than 30 days.
Passing
"auto"
toresConfig
no longer automatically picks string resources to package into your APK. If you continue to use"auto"
, the plugin packages all string resources your app and its dependencies provide. So, you should instead specify each locale that you want the plugin to package into your APK.Because local modules can't depend on your app's test APK, adding dependencies to your instrumented tests using the
androidTestApi
configuration, instead ofandroidTestImplementation
, causes Gradle to issue the following warning:WARNING: Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'
Fixes
- Fixes an issue where Android Studio doesn't properly recognize dependencies in composite builds.
- Fixes an issue where you get a project sync error when loading the Android plugin multiple times in a single build–for example, when multiple subprojects each include the Android plugin in their buildscript classpath.
3.0.0 (October 2017)
Android Gradle plugin 3.0.0 includes a variety of changes that aim to address performance issues of large projects.
For example, on a sample skeleton project with ~130 modules and a large number of external dependencies (but no code or resources), you can experience performance improvements similar to the following:
Android plugin version + Gradle version | Android plugin 2.2.0 + Gradle 2.14.1 | Android plugin 2.3.0 + Gradle 3.3 | Android plugin 3.0.0 + Gradle 4.1 |
---|---|---|---|
Configuration (e.g. running ./gradlew --help ) |
~2 mins | ~9 s | ~2.5 s |
1-line Java change (implementation change) | ~2 mins 15 s | ~29 s | ~6.4 s |
Some of these changes break existing builds. So, you should consider the effort of migrating your project before using the new plugin.
If you don't experience the performance improvements described above, please file a bug and include a trace of your build using the Gradle Profiler.
This version of the Android plugin requires the following:
- Gradle 4.1 or higher. To learn more, read the section about updating Gradle.
- Build Tools 26.0.2 or higher.
With this update, you no longer need to specify a version for the build
tools—the plugin uses the minimum required version by default.
So, you can now remove the
android.buildToolsVersion
property.
3.0.1 (November 2017)
This is a minor update to support Android Studio 3.0.1, and includes general bug fixes and performance improvements.
Optimizations
- Better parallelism for multi-module projects through a fine grained task graph.
- When making changes to dependency, Gradle performs faster builds by not
re-compiling modules that do not have access to that dependency's API.
You should restrict which dependencies leak their APIs to other modules by
using Gradle's new dependency configurations:
implementation
,api
,compileOnly
, andruntimeOnly
. - Faster incremental build speed due to per-class dexing. Each class is now
compiled into separate DEX files, and only the classes that are
modified are re-dexed. You should also expect improved build speeds for
apps that set
minSdkVersion
to 20 or lower, and use legacy multi-dex. - Improved build speeds by optimizing certain tasks to use chached outputs. To benefit from this optimization, you need to first enable the Gradle build cache.
- Improved incremental resource processing using AAPT2, which is now enabled by
default.
If you are experiencing issues while using AAPT2, please
report a bug. You can also disable AAPT2 by
setting
android.enableAapt2=false
in yourgradle.properties
file and restarting the Gradle daemon by running./gradlew --stop
from the command line.
New features
- Variant-aware dependency management. When building a certain variant of a module, the plugin now automatically matches variants of local library module dependencies to the variant of the module you are building.
- Includes a new Feature module plugin to support Android Instant Apps and the Android Instant Apps SDK (which you can download using the SDK manager). To learn more about creating Feature modules with the new plugin, read Structure of an instant app with multiple features.
- Built-in support for using certain Java 8 language features and Java 8 libraries. Jack is now deprecated and no longer required, and you should first disable Jack to use the improved Java 8 support built into the default toolchain. For more information, read Use Java 8 language features.
- Added support for running tests with
Android Test Orchestrator,
which allows you to run each of your app's tests within
its own invocation of
Instrumentation
. Because each test runs in its ownInstrumentation
instance, any shared state between tests doesn't accumulate on your device's CPU or memory. And, even if one test crashes, it takes down only its own instance ofInstrumentation
, so your other tests still run.- Added
testOptions.execution
to determine whether to use on-device test orchestration. If you want to use Android Test Orchestrator, you need to specifyANDROID_TEST_ORCHESTRATOR
, as shown below. By default, this property is set toHOST
, which disables on-device orchestration and is the standard method of running tests.
- Added
android { testOptions { execution 'ANDROID_TEST_ORCHESTRATOR' } }
- New
androidTestUtil
dependency configuration allows you to install another test helper APK before running your instrumentation tests, such as Android Test Orchestrator:
dependencies { androidTestUtil 'com.android.support.test:orchestrator:1.0.0' ... }
- Added
testOptions.unitTests.includeAndroidResources
to support unit tests that require Android resources, such as Roboelectric. When you set this property totrue
, the plugin performs resource, asset, and manifest merging before running your unit tests. Your tests can then inspectcom/android/tools/test_config.properties
on the classpath for the following keys:android_merged_assets
: the absolute path to the merged assets directory.Note: For library modules, the merged assets do not contain the assets of dependencies (see issue #65550419).
android_merged_manifest
: the absolute path to the merged manifest file.android_merged_resources
: the absolute path to the merged resources directory, which contains all the resources from the module and all its dependencies.android_custom_package
: the package name of the final R class. If you dynamically modify the application ID, this package name may not match thepackage
attribute in the app's manifest.
- Support for fonts as resources (which is a new feature introduced in Android 8.0 (API level 26)).
- Support for language-specific APKs with Android Instant Apps SDK 1.1 and higher. For more information, see Configure your build for pure splits.
- You can now change the output directory for your external native build project, as shown below:
android { ... externalNativeBuild { // For ndk-build, instead use the ndkBuild block. cmake { ... // Specifies a relative path for outputs from external native // builds. You can specify any path that's not a subdirectory // of your project's temporary build/ directory. buildStagingDirectory "./outputs/cmake" } } }
- You can now use CMake 3.7 or higher when building native projects from Android Studio.
- New
lintChecks
dependency configuration allows you to build a JAR that defines custom lint rules, and package it into your AAR and APK projects. Your custom lint rules must belong to a separate project that outputs a single JAR and includes onlycompileOnly
dependencies. Other app and library modules can then depend on your lint project using thelintChecks
configuration:
dependencies { // This tells the Gradle plugin to build ':lint-checks' into a lint.jar file // and package it with your module. If the module is an Android library, // other projects that depend on it automatically use the lint checks. // If the module is an app, lint includes these rules when analyzing the app. lintChecks project(':lint-checks') }
Behavior changes
- Android plugin 3.0.0 removes certain APIs, and your build will break if you
use them. For example, you can no longer use the Variants API to access
outputFile()
objects or useprocessManifest.manifestOutputFile()
to get the manifest file for each variant. To learn more, read API changes. - You no longer need to specify a version for the build tools (so, you can now
remove the
android.buildToolsVersion
property). By default, the plugin automatically uses the minimum required build tools version for the version of Android plugin you're using. - You now enable PNG crunching in the
buildTypes
block, as shown below. PNG crunching is enabled by default for all builds except debug builds because it increases build times for projects that include many PNG files. So, to improve build times for other build types, you should either disable PNG crunching or convert your images to WebP.
android { buildTypes { release { // Disables PNG crunching for the release build type. crunchPngs false } } }
- The Android plugin now automatically builds executable targets that you configure in your external CMake projects.
- You must now add annotation processors
to the processor classpath using the
annotationProcessor
dependency configuration. - Using the deprecated
ndkCompile
is now more restricted. You should instead migrate to using either CMake or ndk-build to compile native code that you want to package into your APK. To learn more, read Migrate from ndkcompile.
2.3.0 (February 2017)
2.3.3 (June 2017)
This is a minor update that adds compatibility with Android Studio 2.3.3.
2.3.2 (May 2017)
This is a minor update that adds compatibility with Android Studio 2.3.2.
2.3.1 (April 2017)
This is a minor update to Android plugin 2.3.0 that fixes an issue where some physical Android devices did not work properly with Instant Run (see Issue #235879).
- Dependencies:
-
- Gradle 3.3 or higher.
- Build Tools 25.0.0 or higher.
- New:
-
- Uses Gradle 3.3, which includes performance improvements and new features. For more details, see the Gradle release notes.
-
Build cache: stores certain outputs that the Android plugin generates
when building your project (such as unpackaged AARs and pre-dexed remote
dependencies). Your clean builds are much faster while using the cache because
the build system can simply reuse those cached files during subsequent builds,
instead of recreating them. Projects using Android plugin 2.3.0 and higher use
the build cache by default. To learn more, read Improve Build Speed with Build Cache.
-
Includes a
cleanBuildCache
task that clears the build cache. - If you are using the experimental version of build cache (included in earlier versions of the plugin), you should update your plugin to the latest version.
-
Includes a
- Changes:
-
- Supports changes to Instant Run included in Android Studio 2.3.
- Configuration times for very large projects should be significantly faster.
- Fixed issues with auto-downloading for the constraint layout library.
- Plugin now uses ProGuard version 5.3.2.
- Includes many fixes for reported bugs. Please continue to file bug reports when you encounter issues.
2.2.0 (September 2016)
- Dependencies:
-
- Gradle 2.14.1 or higher.
- Build Tools 23.0.2 or higher.
- New:
-
- Uses Gradle 2.14.1, which includes performance improvements and new features, and fixes a security vulnerability that allows local privilege escalation when using the Gradle daemon. For more details, see the Gradle release notes.
- Using the
externalNativeBuild {}
DSL, Gradle now lets you link to your native sources and compile native libraries using CMake or ndk-build. After building your native libraries, Gradle packages them into your APK. To learn more about using CMake and ndk-build with Gradle, read Add C and C++ Code to Your Project. - When you run a build from the command line, Gradle now attempts to auto-download any missing SDK components or updates that your project depends on. To learn more, read Auto-download missing packages with Gradle.
- A new experimental caching feature lets Gradle speed up build times by pre-dexing, storing, and reusing the pre-dexed versions of your libraries. To learn more about using this experimental feature, read the Build Cache guide.
- Improves build performance by adopting a new default packaging
pipeline which handles zipping, signing, and zipaligning in one task. You
can revert to using the older packaging tools by adding
android.useOldPackaging=true
to yourgradle.properties
file. While using the new packaging tool, thezipalignDebug
task is not available. However, you can create one yourself by calling thecreateZipAlignTask(String taskName, File inputFile, File outputFile)
method. - APK signing now uses APK Signature Scheme
v2 in addition to traditional JAR signing. All Android platforms accept the
resulting APKs. Any modification to these APKs after signing invalidates their
v2 signatures and prevents installation on a device. To disable this feature,
add the following to your module-level
build.gradle
file:android { ... signingConfigs { config { ... v2SigningEnabled false } } }
- For multidex builds, you can now use ProGuard rules to determine which
classes Gradle should compile into your app’s main DEX file. Because
the Android system loads the main DEX file first when starting your app, you
can prioritize certain classes at startup by compiling them into the main DEX
file. After you create a ProGuard configuration file specifically for your
main DEX file, pass the configuration file’s path to Gradle using
buildTypes.multiDexKeepProguard
. Using this DSL is different from usingbuildTypes.proguardFiles
, which provides general ProGuard rules for your app and does not specify classes for the main DEX file. - Adds support for the
android:extractNativeLibs
flag, which can reduce the size of your app when you install it on a device. When you set this flag tofalse
in the<application>
element of your app manifest, Gradle packages uncompressed and aligned versions of your native libraries with your APK. This preventsPackageManager
from copying out your native libraries from the APK to the device's file system during installation and has the added benefit of making delta updates of your app smaller. - You can now specify
versionNameSuffix
andapplicationIdSuffix
for product flavors. (Issue 59614)
- Changes:
-
-
getDefaultProguardFile
now returns the default ProGuard files that Android plugin for Gradle provides and no longer uses the ones in the Android SDK. - Improved Jack compiler performance and features:
- Jack now supports Jacoco test coverage when setting
testCoverageEnabled
totrue
. - Improved support for annotation processors. Annotation
processors on your classpath, such as any
compile
dependencies, are automatically applied to your build. You can also specify an annotation processor in your build and pass arguments by using thejavaCompileOptions.annotationProcessorOptions {}
DSL in your module-levelbuild.gradle
file:android { ... defaultConfig { ... javaCompileOptions { annotationProcessorOptions { className 'com.example.MyProcessor' // Arguments are optional. arguments = [ foo : 'bar' ] } } } }
If you want to apply an annotation processor at compile time but not include it in your APK, use the
annotationProcessor
dependency scope:dependencies { compile 'com.google.dagger:dagger:2.0' annotationProcessor 'com.google.dagger:dagger-compiler:2.0' // or use buildVariantAnnotationProcessor to target a specific build variant }
- You can set additional flags for Jack using
jackOptions.additionalParameters()
. The following code snippet sets thejack.incremental
parameter totrue
:android { defaultConfig { ... jackOptions { enabled true additionalParameters("jack.incremental" : true) } } }
For a list of parameters you can set, run the following from the command line:
java -jar /build-tools/jack.jar --help-properties
- By default, if the Gradle daemon's heap size is at least 1.5
GB, Jack now runs in the same process as Gradle. To adjust the
daemon heap size, add the following to your
gradle.properties
file:# This sets the daemon heap size to 1.5GB. org.gradle.jvmargs=-Xmx1536M
- Jack now supports Jacoco test coverage when setting
-
2.1.0 (April 2016)
2.1.3 (August 2016)
This update requires Gradle 2.14.1 and higher. Gradle 2.14.1 includes performance improvements, new features, and an important security fix. For more details, see the Gradle release notes.
- Dependencies:
-
- Gradle 2.10 or higher.
- Build Tools 23.0.2 or higher.
- New:
-
- Added support for the N Developer Preview, JDK 8, and Java 8 language features using the Jack
toolchain. To find out more, read the N Preview guide.
Note: Instant Run does not currently work with Jack and will be disabled while using the new toolchain. You only need to use Jack if you are developing for the N Preview and want to use the supported Java 8 language features.
- Added default support for incremental Java compilation to reduce
compilation time during development. It does this by only recompiling
portions of the source that have changed or need to be recompiled. To disable
this feature, add the following code to your module-level
build.gradle
file:android { ... compileOptions { incremental false } }
-
Added support for dexing-in-process which performs dexing within the build process rather than in a separate, external VM processes. This not only makes incremental builds faster, but also speeds up full builds. The feature is enabled by default for projects that have set the Gradle daemon's maximum heap size to at least 2048 MB. You can do this by including the following in your project's
gradle.properties
file:org.gradle.jvmargs = -Xmx2048m
If you have defined a value for
javaMaxHeapSize
in your module-levelbuild.gradle
file, you need to setorg.gradle.jvmargs
to the value ofjavaMaxHeapSize
+ 1024 MB. For example, if you have setjavaMaxHeapSize
to "2048m", you need to add the following to your project'sgradle.properties
file:org.gradle.jvmargs = -Xmx3072m
To disable dexing-in-process, add the following code to your module-level
build.gradle
file:android { ... dexOptions { dexInProcess false } }
- Added support for the N Developer Preview, JDK 8, and Java 8 language features using the Jack
toolchain. To find out more, read the N Preview guide.
2.0.0 (April 2016)
- Dependencies:
-
- Gradle 2.10 or higher.
- Build Tools 21.1.1 or higher.
- New:
-
- Enables Instant Run by supporting bytecode injection, and pushing code and resource updates to a running app on the emulator or a physical device.
- Added support for incremental builds, even when the app isn’t running. Full build times are improved by pushing incremental changes through the Android Debug Bridge to the connected device.
- Added
maxProcessCount
to control how many slave dex processes can be spawned concurrently. The following code, in the module-levelbuild.gradle
file, sets the maximum number of concurrent processes to 4:android { ... dexOptions { maxProcessCount = 4 // this is the default value } }
- Added an experimental code shrinker to support pre-dexing and reduce re-dexing
of dependencies, which are not supported with Proguard. This improves the build
speed of your debug build variant. Because the experimental shrinker does not
support optimization and obfuscation, you should enable Proguard for your
release builds. To enable the experimental shrinker for your debug builds, add
the following to your module-level
build.gradle
file:android { ... buildTypes { debug { minifyEnabled true useProguard false } release { minifyEnabled true useProguard true // this is a default setting } } }
- Added logging support and improved performance for the resource shrinker.
The resource shrinker now logs all of its operations into a
resources.txt
file located in the same folder as the Proguard log files.
- Changed behavior:
-
- When
minSdkVersion
is set to 18 or higher, APK signing uses SHA256. - DSA and ECDSA keys can now sign APK packages.
Note: The Android keystore provider no longer supports DSA keys on Android 6.0 (API level 23) and higher.
- When
- Fixed issues:
-
- Fixed an issue that caused duplicate AAR dependencies in both the test and main build configurations.