透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android Gradle 外掛程式 3.4.0 版 (2019 年 4 月)
這個版本的 Android 外掛程式須使用下列項目:
|
最低版本 |
預設版本 |
附註 |
Gradle |
5.1.1 |
5.1.1 |
詳情請參閱「更新 Gradle」相關說明。使用 Gradle 5.0 以上版本時,預設的 Gradle Daemon 記憶體堆積大小會從 1 GB 減少至 512 MB。這可能會造成建構效能迴歸現象。如要覆寫這項預設設定,請在專案的 gradle.properties 檔案中指定 Gradle Daemon 堆積大小。 |
SDK 版本工具 |
28.0.3 |
28.0.3 |
安裝或設定 SDK 版本工具。 |
新功能
行為變更
-
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,脫糖、縮減、模糊化、最佳化和 DEX 處理 (D8) 全都可透過單一步驟完成,如下圖所示。
提醒您,R8 能夠與現有 ProGuard 規則搭配運作,因此您可能不需要採取任何行動就能享有 R8 的好處。不過,由於這與專為 Android 專案設計的 ProGuard 是不同的技術,因此在進行縮減和最佳化時,可能會導致原先 ProGuard 不會移除的程式碼遭到移除。在這類罕見情況下,您可能必須新增額外規則,讓建構輸出內容保留該程式碼。
如果您在使用 R8 時遇到問題,請參閱 R8 相容性常見問題,看看是否有該問題的解決方案。如果當中沒有提供解決方案,請回報錯誤。您可以在專案的 gradle.properties
檔案中加入下列其中一行程式碼來停用 R8:
# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false
注意:針對特定建構類型,如果您在應用程式模組的 build.gradle
檔案中將 useProguard
設為 false
,則不論您是否有在專案的 gradle.properties
檔案中停用 R8,Android Gradle 外掛程式都會使用 R8 縮減該建構類型的應用程式程式碼。
-
ndkCompile
已淘汰:如果您嘗試使用 ndkBuild
編譯原生資料庫,將會收到建構錯誤。建議您改用 CMake 或 ndk-build,為專案新增 C 和 C++ 程式碼。
已知問題
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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"]]