使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Gradle 插件 3.2.0(2018 年 9 月)
此版本的 Android 插件需要使用以下工具:
|
最低版本 |
默认版本 |
备注 |
Gradle |
4.6 |
4.6 |
如需了解详情,请参阅更新 Gradle。 |
SDK Build Tools |
28.0.3 |
28.0.3 |
安装或配置 SDK Build Tools。 |
3.2.1(2018 年 10 月)
通过此次更新,您无需再为 SDK Build Tools 指定版本。Android Gradle 插件现在默认使用版本 28.0.3。
新功能
-
支持构建 Android App Bundle:App Bundle 是一种全新的上传格式,其中包含应用的所有经过编译的代码和资源,但 APK 生成及签名工作则由 Google Play 商店完成。您无需再构建、签署和管理多个 APK,而用户也可以获得更小且已针对其设备优化的下载内容。如需了解详情,请参阅 Android App Bundle 简介一文。
-
支持在使用注解处理器时加快增量构建速度:AnnotationProcessorOptions
DSL 现在会扩展 CommandLineArgumentProvider
,这可让您或注解处理器创建者使用增量 build 属性类型注解来注解处理器的参数。使用这些注解可提高增量和缓存整洁 build 的正确性和性能。如需了解详情,请参阅向注解处理器传递参数部分。
-
适用于 AndroidX 的迁移工具:在搭配使用 Android Gradle 插件 3.2.0 与 Android 3.2 及更高版本时,您可迁移项目的本地依赖项和 Maven 依赖项,以使用新的 AndroidX 库,方法是从菜单栏中依次选择 Refactor > Migrate to AndroidX。使用此迁移工具还会在 gradle.properties
文件中将以下标记设置为 true
:
-
android.useAndroidX
:如果设置为 true
,Android 插件会使用对应的 AndroidX 库,而非支持库。如未指定此标记,该插件会默认将其设置为 false
。
-
android.enableJetifier
:如果设置为 true
,Android 插件会通过重写其二进制文件来自动迁移现有的第三方库,以使用 AndroidX。如未指定此标记,该插件会默认将其设置为 false
。只有在 android.useAndroidX
也被设置为 true
时,您才能将此标记设置为 true
,否则会遇到构建错误。
如需了解详情,请参阅 AndroidX 概览。
-
新的代码缩减器 R8:R8 是一种执行代码缩减和混淆的新工具,替代了 ProGuard。您只需将以下代码添加到项目的 gradle.properties
文件中,即可开始使用 R8 的预览版本:
android.enableR8 = true
android.enableR8 = true
行为变更
-
使用 D8 进行脱糖的功能现已默认处于启用状态。
-
AAPT2 现在位于 Google 的 Maven 制品库中。如需使用 AAPT2,请确保您的 build.gradle
文件中包含 google()
依赖项,如下所示:
buildscript {
repositories {
google() // here
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
allprojects {
repositories {
google() // and here
jcenter()
}
buildscript {
repositories {
google() // here
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
allprojects {
repositories {
google() // and here
jcenter()
}
-
原生 MultiDex 现已默认处于启用状态。以前版本的 Android Studio 会在将应用的调试版本部署到搭载 Android API 级别 21 或更高级别的设备时启用原生 MultiDex。现在,无论您是要部署到设备,还是要构建 APK 以供发布,Android Gradle 插件都会针对所有设置为 minSdkVersion=21
(或更高版本)的模块启用原生多 MultiDex。
-
该插件现在会强制执行最低版本的 protobuf 插件 (0.8.6)、Kotlin 插件 (1.2.50) 和 Crashlytics 插件 (1.25.4)。
-
在指定模块名称时,功能模块插件 com.android.feature
现在强制要求仅使用字母、数字和下划线。例如,如果功能模块名称包含短划线,您会遇到构建错误。此行为与动态功能插件的行为相符。
bug 修复
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-05。
[null,null,["最后更新时间 (UTC):2025-09-05。"],[],[],null,["\u003cbr /\u003e\n\nAndroid Gradle Plugin 3.2.0 (September 2018)\n\nThis version of the Android plugin requires the following:\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:----------------------------------------------------------------------------------------------------------:|\n| Gradle | 4.6 | 4.6 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). |\n| SDK Build Tools | 28.0.3 | 28.0.3 | [Install](/studio/intro/update#sdk-manager) or [configure](/tools/releases/build-tools) SDK Build Tools. |\n\n**3.2.1 (October 2018)**\n\nWith this update, you no longer need to specify a version for the SDK Build\nTools. The Android Gradle plugin now uses version 28.0.3 by default.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nNew features\n\n- **Support for building Android App Bundles:** The app bundle is a new upload\n format that includes all your app's compiled code and resources while\n deferring APK generation and signing to the Google Play Store. You no longer\n have to build, sign, and manage multiple APKs, and users get smaller downloads\n that are optimized for their device. To learn more, read\n [About Android App Bundles](/guide/app-bundle).\n\n- **Support for improved incremental build speeds when using annotation processors:**\n The [`AnnotationProcessorOptions`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.AnnotationProcessorOptions.html)\n DSL now extends [`CommandLineArgumentProvider`](https://docs.gradle.org/current/javadoc/org/gradle/process/CommandLineArgumentProvider.html),\n which enables either you or the annotation processor author to annotate\n arguments for the processor using\n [incremental build property type annotations](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks).\n Using these annotations improves the correctness and performance of\n incremental and cached clean builds. To learn more, read\n [Pass arguments to annotation processors](/studio/build/dependencies#processor-arguments).\n\n- **Migration tool for AndroidX:** When using Android Gradle plugin 3.2.0 with\n Android 3.2 and higher, you can migrate your project's local and Maven\n dependencies to use the new AndroidX libraries by selecting **Refactor \\\u003e\n Migrate to AndroidX** from the menu bar. Using this migration tool also sets\n the following flags to `true` in your `gradle.properties` file:\n\n - **`android.useAndroidX`:** When set to `true`, the Android plugin uses the\n appropriate AndroidX library instead of a Support Library. When this flag\n is not specified, the plugin sets it to `false` by default.\n\n - **`android.enableJetifier`:** When set to `true`, the Android plugin\n automatically migrates existing third-party libraries to use AndroidX by\n rewriting their binaries. When this flag is not specified, the plugin sets\n it to `false` by default. You can set this flag to `true` only while\n `android.useAndroidX` is also set to `true`, otherwise you get a build error.\n\n To learn more, read the [AndroidX overview](/topic/libraries/support-library/androidx-overview).\n- **New code shrinker, R8:** R8 is a new tool for code shrinking and obfuscation\n that replaces ProGuard. You can start using the preview version of R8 by\n including the following in your project's `gradle.properties` file:\n\n ```groovy\n android.enableR8 = true\n \n ``` \n\n ```kotlin\n android.enableR8 = true\n \n ```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nBehavior changes\n\n- Desugaring with D8 is now enabled by default.\n\n- AAPT2 is now on Google's Maven repo. To use AAPT2, make sure that you\n have the `google()` dependency in your `build.gradle`\n file, as shown below:\n\n ```groovy\n buildscript {\n repositories {\n google() // here\n jcenter()\n }\n dependencies {\n classpath 'com.android.tools.build:gradle:3.2.0'\n }\n }\n allprojects {\n repositories {\n google() // and here\n jcenter()\n }\n \n ``` \n\n ```kotlin\n buildscript {\n repositories {\n google() // here\n jcenter()\n }\n dependencies {\n classpath 'com.android.tools.build:gradle:3.2.0'\n }\n }\n allprojects {\n repositories {\n google() // and here\n jcenter()\n }\n \n ```\n- Native multidex is now enabled by default. Previous versions of Android\n Studio enabled native multidex when deploying the debug version of an app to a\n device running Android API level 21 or higher. Now, whether you're deploying\n to a device or building an APK for release, the Android Gradle plugin\n enables native multidex for all modules that set\n `minSdkVersion=21` or higher.\n\n- The plugin now enforces a minimum version of the protobuf plugin (0.8.6),\n Kotlin plugin (1.2.50), and Crashlytics plugin (1.25.4).\n\n- The feature module plugin,`com.android.feature`, now\n enforces the use of only letters, digits, and underscores when specifying\n a module name. For example, if your feature module name includes dashes,\n you get a build error. This behavior matches that of the dynamic feature\n plugin.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nBug fixes\n\n- JavaCompile is now cacheable in projects with data binding. ([Issue #69243050](https://issuetracker.google.com/69243050))\n- Better compile avoidance for library modules with data binding. ([Issue #77539932](https://issuetracker.google.com/77539932))\n- You can now re-enable [configure-on-demand](https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:configuration_on_demand) if you've disable it in earlier versions due to some unpredictable build errors. ([Issue #77910727](https://issuetracker.google.com/77910727))\n\n\u003cbr /\u003e"]]