使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Gradle 插件 3.4.0(2019 年 4 月)
此版本的 Android 插件需要使用以下工具:
|
最低版本 |
默认版本 |
备注 |
Gradle |
5.1.1 |
5.1.1 |
如需了解详情,请参阅更新 Gradle。如果使用的是 Gradle 5.0 及更高版本,默认的 Gradle 守护程序内存堆大小会从 1 GB 降到 512 MB。这可能会导致构建性能降低。如需替换此默认设置,请在项目的 gradle.properties 文件中指定 Gradle 守护进程堆大小。 |
SDK Build Tools |
28.0.3 |
28.0.3 |
安装或配置 SDK Build Tools。 |
3.4.3(2020 年 7 月)
此次要更新支持与 Android 11 中软件包可见性的新默认设置和功能兼容。
如需了解详情,请参阅 4.0.1 版本说明。
3.4.2(2019 年 7 月)
此次要更新对 Android Studio 3.4.2 构成补充,修复了各种 bug 并进行了多项性能改进。要查看重要问题修复列表,请阅读版本更新博客上的相关博文。
3.4.1(2019 年 5 月)
此次要更新对 Android Studio 3.4.1 构成补充,修复了各种 bug 并进行了多项性能改进。要查看重要问题修复列表,请阅读版本更新博客上的相关博文。
新功能
行为变更
-
Android 免安装应用功能插件废弃警告:如果您仍在使用 com.android.feature
插件构建免安装应用,Android Gradle 插件 3.4.0 会向您发出废弃警告。为了确保您仍然可以在未来版本的插件上构建您的免安装应用,请迁移免安装应用,以使用动态功能插件,这样您还可以通过单个 Android App Bundle 发布安装式应用和免安装应用。
-
R8 默认处于启用状态:R8 将脱糖、压缩、混淆、优化和 dex 处理整合到了一个步骤中,从而显著提高了构建性能。R8 是在 Android Gradle 插件 3.3.0 中引入的,对于使用插件 3.4.0 及更高版本的应用和 Android 库项目,R8 现已默认处于启用状态。
下图是引入 R8 之前的编译流程的简要概览。
现在,有了 R8,可以在一个步骤中完成脱糖、压缩、混淆、优化和 dex 处理 (D8),如下图所示。
请注意,R8 旨在与您现有的 ProGuard 规则配合使用,因此您可能不需要采取任何操作即可从 R8 中受益。但是,相对专为 Android 项目设计的 ProGuard 而言,R8 是一项不同的技术,因此压缩和优化可能会导致移除 ProGuard 可能没有的代码。因此,在这种情况(尽管不太可能发生)下,您可能需要添加其他规则,以在 build 输出中保留这些代码。
如果您在使用 R8 时遇到问题,请参阅 R8 兼容性常见问题解答一文,以检查是否有针对您的问题的解决方案。如果没有记录的解决方案,请报告 bug。您可以停用 R8,只需将以下其中一行内容添加到项目的 gradle.properties
文件即可:
# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false
注意:对于指定 build 类型,如果您在应用模块的 build.gradle
文件中将 useProguard
设置为 false
,Android Gradle 插件会使用 R8 压缩该 build 类型的应用代码,无论您是否在项目的 gradle.properties
文件中停用 R8 都是如此。
-
ndkCompile
已废弃:现在,如果您尝试使用 ndkBuild
编译原生库,将会遇到构建错误。您应改用 CMake 或 ndk-build 将 C 和 C++ 代码添加到项目中。
已知问题
本页面上的内容和代码示例受内容许可部分所述许可的限制。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.4.0 (April 2019)\n\nThis version of the Android plugin requires the following:\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| Gradle | 5.1.1 | 5.1.1 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). When using Gradle 5.0 and higher, the default Gradle daemon memory heap size decreases from 1 GB to 512 MB. This might result in a build performance regression. To override this default setting, specify the Gradle daemon heap size in your project's gradle.properties file. |\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.4.3 (July 2020)**\n\n\nThis minor update supports compatibility with new default settings and\nfeatures for\n[package visibility\nin Android 11](/about/versions/11/privacy/package-visibility).\n\n\nSee the [4.0.1 release notes](#4.0.1) for details.\n\n**3.4.2 (July 2019)**\n\n\nThis minor update supports Android Studio 3.4.2 and includes various bug\nfixes and performance improvements.\nTo see a list of noteable bug fixes, read the related post on the\n[Release Updates blog](https://androidstudio.googleblog.com/2019/07/android-studio-342-available.html).\n\n**3.4.1 (May 2019)**\n\n\nThis minor update supports Android Studio 3.4.1 and includes various bug\nfixes and performance improvements.\nTo see a list of noteable bug fixes, read the related post on the\n[Release Updates blog](https://androidstudio.googleblog.com/2019/05/android-studio-341-available.html).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nNew features\n\n- **New lint check dependency configurations:** The\n behavior of `lintChecks` has changed and a new dependency\n configuration, `lintPublish`, has been introduced to give\n you more control over which lint checks are packaged in your Android\n libraries.\n\n - `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 the `lintChecks` dependency configuration to include lint checks in the published AAR, you need to migrate those dependencies to instead use the new `lintPublish` configuration described below.\n - `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.\n\n The following code sample uses both dependency configurations in a\n local Android library project. \n\n ```groovy\n dependencies {\n // Executes lint checks from the ':lint' project at build time.\n lintChecks project(':lint')\n // Packages lint checks from the ':lintpublish' in the published AAR.\n lintPublish project(':lintpublish')\n }\n \n ``` \n\n ```kotlin\n dependencies {\n // Executes lint checks from the ':lint' project at build time.\n lintChecks(project(\":lint\"))\n // Packages lint checks from the ':lintpublish' in the published AAR.\n lintPublish(project(\":lintpublish\"))\n }\n \n ```\n - In general, packaging and signing tasks should see an overall build\n speed improvement. If you notice a performance regression related to\n these tasks, please [report a bug](/studio/report-bugs).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nBehavior changes\n\n- **Android Instant Apps Feature plugin deprecation\n warning:** If you're still using the\n `com.android.feature` plugin to build your instant app,\n Android Gradle plugin 3.4.0 will give throw you a deprecation warning.\n To make sure you can still build you instant app on future versions of\n the plugin, migrate your instant app to using\n [the dynamic feature plugin](/studio/projects/dynamic-delivery),\n which also allows you to publish both your installed and instant app\n experiences from a single Android App Bundle.\n\n- **R8 enabled by default:** R8 integrates desugaring,\n shrinking, obfuscating, optimizing, and dexing all in one step---resulting\n in\n [noticeable build performance\n improvements](https://www.google.com/url?q=https://android-developers.googleblog.com/2018/11/r8-new-code-shrinker-from-google-is.html&sa=D&ust=1551922493258000&usg=AFQjCNH0N1wuMX645n7giw0wjikzjm3WCA). R8 was introduced in Android Gradle plugin 3.3.0 and\n is now enabled by default for both app and Android library projects\n using plugin 3.4.0 and higher.\n\nThe image below provides a high-level overview of the compile process\nbefore R8 was introduced.\n\nNow, with R8, desugaring, shrinking, obfuscating, optimizing, and dexing (D8)\nare all completed in one step, as illustrated below.\n\nKeep in mind, R8 is designed to work with your existing ProGuard rules, so\nyou'll likely not need to take any actions to benefit from R8. However,\nbecause it's a different technology to ProGuard that's designed specifically\nfor Android projects, shrinking and optimization may result in removing code\nthat ProGuard may have not. So, in this unlikely situation, you might need\nto add additional rules to keep that code in your build output.\n\nIf you experience issues using R8, read the\n[R8 compatibility FAQ](https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md)\nto check if there's a solution to your issue. If a solution isn't documented,\nplease [report a bug](https://issuetracker.google.com/issues/new?component=326788&template=1025938).\nYou can disable R8 by adding one of the following lines to your project's\n`gradle.properties` file: \n\n # Disables R8 for Android Library modules only.\n android.enableR8.libraries = false\n # Disables R8 for all modules.\n android.enableR8 = false\n \n \n**Note:** For a given build type, if you set\n`useProguard` to `false` in your app\nmodule's `build.gradle` file, the Android Gradle plugin uses R8\nto shrink your app's code for that build type, regardless of whether you\ndisable R8 in your project's `gradle.properties` file.\n\n- **`ndkCompile` is deprecated:** You now get a build error if you try to use `ndkBuild` to compile your native libraries. You should instead use either CMake or ndk-build to [Add C and C++ code to your\n project](/studio/projects/add-native-code).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nKnown issues\n\n- The correct usage of unique package names are currently not enforced\n but will become more strict on later versions of the plugin. On Android\n Gradle plugin version 3.4.0, you can opt-in to check whether your\n project declares acceptable package names by adding the line below to\n your `gradle.properties` file.\n\n android.uniquePackageNames = true\n \n \n To learn more about setting a package name through the Android Gradle\n plugin, see\n [Set the application ID](/studio/build/configure-app-module#set_the_application_id).\n\n\u003cbr /\u003e"]]