透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android Gradle 外掛程式 3.1.0 版 (2018 年 3 月)
這個版本的 Android 外掛程式須使用下列項目:
|
最低版本 |
預設版本 |
附註 |
Gradle |
4.4 |
4.4 |
詳情請參閱「更新 Gradle」一節。 |
SDK 版本工具 |
27.0.3 |
27.0.3 |
安裝或設定 SDK 版本工具。請注意,您不必再使用 android.buildToolsVersion 屬性為建構工具指定版本,外掛程式會預設使用最低需求版本。 |
全新 DEX 編譯器 D8
Android Studio 現在預設會使用名為 D8 的全新 DEX 編譯器。DEX 編譯是指將 .class
位元碼轉換為 .dex
位元碼,以供 Android 執行階段 (或舊版 Android 的 Dalvik) 使用的程序。與先前名為 DX 的編譯器相較,D8 的編譯速度更快,且輸出的 DEX 檔案更小,同時還能提供相同等級或更優異的應用程式執行階段效能。
D8 應該不會改變您日常的應用程式開發工作流程。不過,如果發生任何和新編譯器有關的問題,請回報錯誤。如要暫時停用 D8 並使用 DX,可以在專案的 gradle.properties
檔案中加入以下內容:
android.enableD8=false
如果專案使用 Java 8 語言功能,系統預設會啟用漸進式脫糖功能。如要停用此功能,可以在專案的 gradle.properties
檔案內指定以下內容:
android.enableIncrementalDesugaring=false.
預先發布版使用者:請注意,如果您已在使用 D8 的預先發布版,D8 現在會使用 SDK 建構工具 (而非 JDK) 內的程式庫進行編譯。因此,假如您要存取的 API 位於 JDK 內,但不在 SDK 建構工具程式庫內,便會發生編譯錯誤。
行為變更
-
如要建構多個 APK,且每個 API 分別指定不同的 ABI,則在預設情況下,外掛程式不會再為下列 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 外掛程式會發生專案同步處理錯誤,例如在處理多個子專案的情況下,每個子專案的建構指令碼類別路徑內都包含該 Android 外掛程式,就會發生錯誤。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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.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"]]