使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Gradle 插件 3.1.0(2018 年 3 月)
此版本的 Android 插件需要使用以下工具:
|
最低版本 |
默认版本 |
备注 |
Gradle |
4.4 |
4.4 |
如需了解详情,请参阅更新 Gradle。 |
SDK Build Tools |
27.0.3 |
27.0.3 |
安装或配置 SDK Build Tools。请注意,您不必再使用 android.buildToolsVersion 属性来指定 Build Tools 的版本。默认情况下,该插件会使用所需的最低版本。 |
新的 DEX 编译器 (D8)
默认情况下,Android Studio 现在会使用名为 D8 的新 DEX 编译器。DEX 编译是指针对 Android 运行时(对于较早版本的 Android,则针对 Dalvik)将 .class
字节码转换为 .dex
字节码的过程。与之前的编译器(称为 DX)相比,D8 的编译速度更快,输出的 DEX 文件更小,同时却能保持相同甚至更出色的应用运行时性能。
D8 应该不会改变您的日常应用开发工作流程。但是,如果您遇到与新编译器有关的任何问题,请报告 bug。您可以在项目的 gradle.properties
文件中添加以下代码,暂时停用 D8 并使用 DX:
android.enableD8=false
对于使用 Java 8 语言功能的项目,系统会默认启用增量脱糖。您可以在项目的 gradle.properties
文件中添加以下代码,停用增量脱糖:
android.enableIncrementalDesugaring=false.
预览版用户:如果您已在使用预览版 D8,则请注意,D8 现在会针对 SDK Build Tools(而非 JDK)中包含的库进行编译。因此,如果您访问的 API 存在于 JDK 而非 SDK Build Tools 库中,则会收到编译错误。
行为变更
-
在构建分别以不同 ABI 为目标的多个 APK 时,默认情况下,插件不会再针对以下 ABI 生成 APK:mips
、mips64
和 armeabi
。
如果您想构建以上述 ABI 为目标的 APK,必须使用 NDK r16b 或更低版本,并在 build.gradle
文件中指定这些 ABI,如下所示:
splits {
abi {
include 'armeabi', 'mips', 'mips64'
...
}
}
splits {
abi {
include("armeabi", "mips", "mips64")
...
}
}
-
现在,Android 插件的构建缓存会排除超过 30 天的缓存条目。
-
将 "auto"
传递给 resConfig
不会再自动选择要打包到 APK 中的字符串资源。如果继续使用 "auto"
,该插件会打包应用及其依赖项提供的所有字符串资源。因此,您应该指定希望插件打包到 APK 中的各个语言区域。
-
由于本地模块不能依赖应用的测试 APK,因此使用 androidTestApi
配置(而非 androidTestImplementation
)将依赖项添加到插桩测试中会导致 Gradle 发出以下警告:
WARNING: Configuration 'androidTestApi' is obsolete
and has been replaced with 'androidTestImplementation'
WARNING: Configuration 'androidTestApi' is obsolete
and has been replaced with 'androidTestImplementation'
修复的问题
- 修复了 Android Studio 无法正确识别复合构建中的依赖项这一问题。
- 修复了以下问题:如果在进行单次构建时多次加载 Android 插件(例如,有多个子项目,并且每个子项目的 buildscript 类路径中都包含 Android 插件),您会遇到项目同步错误。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-30。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-30。"],[],[],null,["\u003cbr /\u003e\n\nAndroid Gradle Plugin 3.1.0 (March 2018)\n\nThis version of the Android plugin requires the following:\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| Gradle | 4.4 | 4.4 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). |\n| SDK Build Tools | 27.0.3 | 27.0.3 | [Install](/studio/intro/update#sdk-manager) or [configure](/tools/releases/build-tools) SDK Build Tools. 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. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nNew DEX compiler, D8\n\nBy default, Android Studio now uses a new DEX compiler called D8. DEX\ncompilation is the process of transforming `.class` bytecode into\n`.dex` bytecode for the Android Runtime (or Dalvik, for older\nversions of Android). Compared to the previous compiler, called DX, D8\ncompiles faster and outputs smaller DEX files, all while having the same or\nbetter app runtime performance.\n\nD8 shouldn't change your day-to-day app development workflow. However, if\nyou experience any issues related to the new compiler, please\n[report a bug](/studio/report-bugs). You can temporarily\ndisable D8 and use DX by including the following in your project's\n`gradle.properties` file: \n\n android.enableD8=false\n \nFor projects that\n[use Java 8 language features](/studio/write/java8-support),\nincremental desugaring is enabled by default. You can disable it by\nspecifying the following in your project's `gradle.properties` file: \n\n android.enableIncrementalDesugaring=false.\n \n\n**Preview users:** If you're already using a preview version of D8, note\nthat it now compiles against libraries included in the\n[SDK build tools](/studio/releases/build-tools)---not the JDK.\nSo, if you are accessing APIs that exist in the JDK but not in the SDK build\ntools libraries, you get a compile error.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nBehavior changes\n\n- When building multiple APKs that each target a different ABI, the\n no longer generates APKs for the following ABIs by default:\n `mips`, `mips64`, and `armeabi`.\n\n If you want to build APKs that target these ABIs, you must use\n [NDK r16b or lower](/ndk/downloads/revision_history) and\n specify the ABIs in your `build.gradle` file, as shown below: \n\n ```groovy\n splits {\n abi {\n include 'armeabi', 'mips', 'mips64'\n ...\n }\n }\n \n ``` \n\n ```kotlin\n splits {\n abi {\n include(\"armeabi\", \"mips\", \"mips64\")\n ...\n }\n }\n \n ```\n- The Android plugin's [build\n cache](/studio/build/build-cache) now evicts cache entries that are older than 30 days.\n\n- Passing `\"auto\"` to\n [`resConfig`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ProductFlavor.html#com.android.build.gradle.internal.dsl.ProductFlavor:resConfig(java.lang.String))\n no longer automatically picks string resources to package into your APK.\n If you continue to use `\"auto\"`, the plugin packages all string\n resources your app and its dependencies provide. So, you should instead\n specify each locale that you want the plugin to package into your APK.\n\n- Because local modules can't depend on your app's test APK, adding\n dependencies to your instrumented tests using the\n `androidTestApi` configuration, instead of\n `androidTestImplementation`, causes Gradle to issue the\n following warning:\n\n ```groovy\n WARNING: Configuration 'androidTestApi' is obsolete\n and has been replaced with 'androidTestImplementation'\n \n ``` \n\n ```kotlin\n WARNING: Configuration 'androidTestApi' is obsolete\n and has been replaced with 'androidTestImplementation'\n \n ```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nFixes\n\n- Fixes an issue where Android Studio doesn't properly recognize dependencies in composite builds.\n- 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.\n\n\u003cbr /\u003e"]]