The Android Studio build system is based on Gradle, and the Android plugin for Gradle 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 Plugin for Gradle
When you update Android Studio, you may receive a prompt to automatically update the Android plugin for 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.
You can specify the Android plugin for
Gradle 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 Android plugin for Gradle to version 2.3.3 from the
build.gradle file:
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
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 plugin for Gradle. For the best performance, you should use the latest possible version of both Gradle and the Android 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+ |
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 3.3 in the
gradle-wrapper.properties file.
... distributionUrl = https\://services.gradle.org/distributions/gradle-3.3-all.zip ...
Revisions
For a summary of known issues in Android plugin for Gradle, see the Known Issues page.
Android plugin for Gradle, revision 2.3.2 (May 2017)
- This is a minor update that adds compatibility with Android Studio 2.3.2.
Android plugin for Gradle, revision 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).
Android plugin for Gradle, revision 2.3.0 (February 2017)
- 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
cleanBuildCachetask 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.
Android plugin for Gradle, revision 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=trueto yourgradle.propertiesfile. While using the new packaging tool, thezipalignDebugtask 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.gradlefile: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:extractNativeLibsflag, which can reduce the size of your app when you install it on a device. When you set this flag tofalsein the<application>element of your app manifest, Gradle packages uncompressed and aligned versions of your native libraries with your APK. This preventsPackageManagerfrom 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
versionNameSuffixandapplicationIdSuffixfor product flavors. (Issue 59614)
- Changes:
-
-
getDefaultProguardFilenow 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
testCoverageEnabledtotrue. - Improved support for annotation processors. Annotation
processors on your classpath, such as any
compiledependencies, 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.gradlefile: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
annotationProcessordependency 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.incrementalparameter 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.propertiesfile:# This sets the daemon heap size to 1.5GB. org.gradle.jvmargs=-Xmx1536M
- Jack now supports Jacoco test coverage when setting
-
Android plugin for Gradle, revision 2.1.3 (August 2016)
- Dependencies:
-
- Gradle 2.14.1 or higher.
- Build Tools 23.0.2 or higher.
- This update adds compatibility with Gradle 2.14.1, which includes performance improvements, new features, and an important security fix. For more details, see the Gradle release notes.
Android plugin for Gradle, revision 2.1.0 (April 2016)
- 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.gradlefile: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.propertiesfile:org.gradle.jvmargs = -Xmx2048m
If you have defined a value for
javaMaxHeapSizein your module-levelbuild.gradlefile, you need to setorg.gradle.jvmargsto the value ofjavaMaxHeapSize+ 1024 MB. For example, if you have setjavaMaxHeapSizeto "2048m", you need to add the following to your project'sgradle.propertiesfile:org.gradle.jvmargs = -Xmx3072m
To disable dexing-in-process, add the following code to your module-level
build.gradlefile: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.
Android plugin for Gradle, revision 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
maxProcessCountto control how many slave dex processes can be spawned concurrently. The following code, in the module-levelbuild.gradlefile, 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.gradlefile: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.txtfile located in the same folder as the Proguard log files.
- Changed behavior:
-
- When
minSdkVersionis 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.
Android plugin for Gradle, revision 1.5.0 (November 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Integrated the Data Binding Plugin into the Android plugin for Gradle. To enable it, add
the following code to each per-project
build.gradlefile that uses the plugin:
android { dataBinding { enabled = true } }- Added a new Transform API to allow third-party plugins to manipulate compiled
.classfiles before they’re converted to.dexfiles. The Transform API simplifies injecting custom class manipulations while offering more flexibility regarding what you can manipulate. To insert a transform into a build, create a new class implementing one of theTransforminterfaces, and register it withandroid.registerTransform(theTransform)orandroid.registerTransform(theTransform, dependencies). There’s no need to wire tasks together. Note the following about the Transform API:- A transform can apply to one or more of the following: the current project, subprojects, and external libraries.
- A transform must be registered globally, which applies them to all variants.
- Internal code processing, through the Java Code Coverage Library (JaCoCo), ProGuard,
and MultiDex, now uses the Transform API. However, the Java Android Compiler Kit
(Jack) doesn’t use this API: only the
javac/dxcode path does. - Gradle executes the transforms in this order: JaCoCo, third-party plugins, ProGuard. The execution order for third-party plugins matches the order in which the transforms are added by the third party plugins; third-party plugin developers can't control the execution order of the transforms through an API.
- Deprecated the
dexgetter from theApplicationVariantclass. You can't access theDextask through the variant API anymore because it’s now accomplished through a transform. There's currently no replacement for controlling the dex process.- Fixed incremental support for assets.
- Improved MultiDex support by making it available for test projects, and tests now automatically have the
com.android.support:multidex-instrumentationdependency.- Added the ability to properly fail a Gradle build and report the underlying error cause when the Gradle build invokes asynchronous tasks and there’s a failure in the worker process.
- Added support for configuring a specific Application Binary Interface (ABI) in variants that contain multiple ABIs.
- Added support for a comma-separated list of device serial numbers for the
ANDROID_SERIALenvironment variable when installing or running tests.- Fixed an installation failure on devices running Android 5.0 (API level 20) and higher when the APK name contains a space.
- Fixed various issues related to the Android Asset Packaging Tool (AAPT) error output.
- Added JaCoCo incremental instrumentation support for faster incremental builds. The Android plugin for Gradle now invokes the JaCoCo instrumenter directly. To force a newer version of the JaCoCo instrumenter, you need to add it as a build script dependency.
- Fixed JaCoCo support so it ignores files that aren’t classes.
- Added vector drawable support for generating PNGs at build time for backward-compatibility. Android plugin for Gradle generates PNGs for every vector drawable found in a resource directory that doesn’t specify an API version or specifies an
android:minSdkVersionattribute of 20 or lower in the<uses-sdk>element in the app manifest. You can set PNG densities by using thegeneratedDensitiesproperty in thedefaultConfigorproductFlavorsections of abuild.gradlefile.- Added sharing of the mockable
android.jar, which the plugin generates only once and uses for unit testing. Multiple modules, such asappandlib, now share it. Delete$rootDir/buildto regenerate it.- Changed the processing of Java resources to occur before the obfuscation tasks instead of during the packaging of the APK. This change allows the obfuscation tasks to have a chance to adapt the Java resources following packages obfuscation.
- Fixed an issue with using Java Native Interface (JNI) code in the experimental library plugin.
- Added the ability to set the platform version separately from the
android:compileSdkVersionattribute in the experimental library plugin. - Integrated the Data Binding Plugin into the Android plugin for Gradle. To enable it, add
the following code to each per-project
Android plugin for Gradle, revision 1.3.1 (August 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Fixed the ZipAlign task to properly consume the output of the previous task when using a customized filename.
- Fixed Renderscript packaging with the NDK.
- Maintained support for the
createDebugCoverageReportbuild task. - Fixed support for customized use of the
archiveBaseNameproperty in thebuild.gradlebuild> file. - Fixed the
Invalid ResourceTypelint warning caused by parameter method annotation lookup when running lint outside of Android Studio.
Android plugin for Gradle, revision 1.3.0 (July 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Added support for the
com.android.build.threadPoolSizeproperty to control theAndroidtask thread pool size from thegradle.propertiesfile or the command line. The following example sets this property to 4.-Pcom.android.build.threadPoolSize=4
- Set the default build behavior to exclude
LICENSEandLICENSE.txtfiles from APKs. To include these files in an APK, remove these files from thepackagingOptions.excludesproperty in thebuild.gradlefile. For example:android { packagingOptions.excludes = [] } - Added the
sourceSetstask to inspect the set of all available source sets. - Enhanced unit test support to recognize multi-flavor and
build variant source folders. For example, to test an app with multi-flavors
flavor1andflavorAwith theDebugbuild type, the test source sets are:- test
- testFlavor1
- testFlavorA
- testFlavor1FlavorA
- testFlavor1FlavorADebug
Android tests already recognized multi-flavor source folders.
- Improved unit test support to:
- Run
javacon main and test sources, even if theuseJackproperty is set totruein your build file. - Correctly recognize dependencies for each build type.
- Run
- Added support for specifying instrumentation test-runner arguments from the command line.
For example:
./gradlew connectedCheck \ -Pandroid.testInstrumentationRunnerArguments.size=medium \ -Pandroid.testInstrumentationRunnerArguments.class=TestA,TestB
- Added support for arbitrary additional Android Asset Packaging Tool (AAPT) parameters
in the
build.gradlefile. For example:android { aaptOptions { additionalParameters "--custom_option", "value" } } - Added support for a
test APK module as a separate test module, using the
targetProjectPathandtargetVariantproperties to set the APK path and target variant.Note: A test APK module does not support product flavors and can only target a single variant. Also, Jacoco is not supported yet.
- Added resource name validation before merging resources.
- When building an AAR (Android ARchive) package for library modules, do not provide an
automatic
@{applicationId}placeholder in the manifest merger settings. Instead, use a different placeholder, such as@{libApplicationId}and provide a value for it if you want to include application Ids in the archive library.
- Added support for the
Android plugin for Gradle, revision 1.2.0 (April 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Enhanced support for running unit tests with Gradle.
- Added support to include Java-style resources in the classpath when running unit tests directly from Gradle.
- Added unit test dependency support for Android ARchive (AAR) artifacts.
- Added support for the
unitTestVariantsproperty so unit test variants can be manipulated using thebuild.gradlefile. - Added the
unitTest.allcode block undertestOptionsto configure customized tasks for unit test. The following sample code shows how to add unit test configuration settings using this new option:android { testOptions { unitTest.all { jvmArgs '-XX:MaxPermSize=256m' // Or any other gradle option. } } } - Fixed the handling of enums and public instance fields in the packaging of the
mockable-android.jarfile. - Fixed library project task dependencies so test classes recompile after changes.
- Added the
testProguardFileproperty to apply ProGuard files when minifying a test APK. - Added the
timeOutproperty to theadbOptionscode block for setting the maximum recording time for Android Debug Bridge screen recording. - Added support for 280 dpi resources.
- Improved performance during project evaluation.
Android plugin for Gradle, revision 1.1.3 (March 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Fixed issue with duplicated dependencies on a test app that triggered a ProGuard failure.
- Fixed Comparator implementation which did not comply with the JDK Comparator contract and generated a JDK 7 error.
Android plugin for Gradle, revision 1.1.2 (February 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Normalized path when creating a mockable JAR for unit testing.
- Fixed the
archivesBaseNamesetting in thebuild.gradlefile. - Fixed the unresolved placeholder failure in manifest merger when building a library test application.
Android plugin for Gradle, revision 1.1.1 (February 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Modified build variants so only variants that package a Wear app trigger Wear-specific build tasks.
- Changed dependency related issues to fail at build time rather than at debug time. This behavior allows you to run diagnostic diagnostic tasks (such as 'dependencies') to help resolve the conflict.
- Fixed the
android.getBootClasspath()method to return a value.
Android plugin for Gradle, revision 1.1.0 (February 2015)
- Dependencies:
-
- Gradle 2.2.1 or higher.
- Build Tools 21.1.1 or higher.
- General Notes:
-
- Added new unit test support
- Enabled
unit tests to
run on the local JVM against a special version of the
android.jarfile that is compatible with popular mocking frameworks, for example Mockito. - Added new test tasks
testDebug,testRelease, andtestMyFlavorDebugwhen using product flavors. - Added new source folders recognized as unit tests:
src/test/java/,src/testDebug/java/,src/testMyFlavor/java/. - Added new configurations in the
build.gradlefile for declaring test-only dependencies, for example,testCompile 'junit:junit:4.11',testMyFlavorCompile 'some:library:1.0'.Note: Test-only dependencies are not currently compatible with Jack (Java Android Compiler Kit).
- Added the
android.testOptions.unitTests.returnDefaultValuesoption to control the behaviour of the mockable android.jar. - Replaced
Testin test task names withAndroidTest. For example, theassembleDebugTesttask is nowassembleDebugAndroidTesttask. Unit test tasks still haveUnitTestin the task name, for exampleassembleDebugUnitTest. - Modified ProGuard configuration files to no longer apply to the test APK. If minification is enabled, ProGuard processes the test APK and applies only the mapping file that is generated when minifying the main APK.
- Updated dependency management
- Fixed issues using
providedandpackagescopes.Note: These scopes are incompatible with AAR (Android ARchive) packages and will cause a build with AAR packages to fail.
- Modified dependency resolution to compare the dependencies of an app under test and the test app. If an artifact with the same version is found for both apps, it's not included with the test app and is packaged only with the app under test. If an artifact with a different version is found for both apps, the build fails.
- Added support for
anyDpiresource qualifier in resource merger. - Improved evaluation and IDE sync speeds for projects with a large number of Android modules.
Android plugin for Gradle, revision 1.0.1 (January 2015)
- Dependencies:
-
- Gradle 2.2.1 up to 2.3.x.
Note: This version of the Android plugin for Gradle is not compatible with Gradle 2.4 and higher.
- Build Tools 21.1.1 or higher.
- Gradle 2.2.1 up to 2.3.x.
- General Notes:
-
- Fixed issue with Gradle build failure when accessing the
extractReleaseAnnotationsmodule. (Issue 81638). - Fixed issue with
Disablepassing the--no-optimizesetting to the Dalvik Executable (dex) bytecode. (Issue 82662). - Fixed manifest merger issues when importing libraries with a
targetSdkVersionless than 16. - Fixed density ordering issue when using Android Studio with JDK 8.
- Fixed issue with Gradle build failure when accessing the
Android plugin for Gradle, revision 1.0.0 (December 2014)
- Dependencies:
-
- Gradle 2.2.1 up to 2.3.x.
Note: This version of the Android plugin for Gradle is not compatible with Gradle 2.4 and higher.
- Build Tools 21.1.1 or higher.
- Gradle 2.2.1 up to 2.3.x.
- General Notes:
-
- Initial plugin release.