透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android Gradle 外掛程式 7.2.0 版 (2022 年 5 月)
Android Gradle 外掛程式 7.2.0 是主要版本,內含多種新功能及改善項目。
7.2.2 (2022 年 8 月)
本次要更新配合 Android Studio Chipmunk 修補程式 2 版本,並修正下列錯誤:
- 問題 #232438924:與 ASM API 搭配使用時,Android Gradle 外掛程式 7.2 版會造成轉換 API 中斷
- 問題 #231037948:AGP 7.2.0-rc01 :buildSrc:generatePrecompiledScriptPluginAccessors - shadow/bundletool/com/android/prefs/AndroidLocation$AndroidLocationException
7.2.1 版 (2022 年 5 月)
本次要更新配合 Android Studio Chipmunk 修補程式 1 版本,並修正下列錯誤:
如要查看此版本包含的其他錯誤修正,請參閱 Android Studio Chipmunk 修補程式 1 版本資訊。
相容性
|
最低版本 |
預設版本 |
附註 |
Gradle |
7.3.3 |
7.3.3 |
詳情請參閱「更新 Gradle」一節。 |
SDK 版本工具 |
30.0.3 |
30.0.3 |
安裝或設定 SDK 版本工具。 |
NDK |
不適用 |
21.4.7075529 |
安裝或設定 NDK 其他版本。 |
JDK |
11 |
11 |
詳情請參閱「設定 JDK 版本」相關說明。 |
版本分析器中的 Jetifier 警告和檢查
如果專案的 gradle.properties
檔案包含 android.enableJetifier=true
,版本分析器現在會顯示警告。這個旗標是在先前的 Android Studio 版本中所推出,用於針對未原生支援 AndroidX 的程式庫啟用 AndroidX。不過,程式庫生態系統大多都已改為原生支援 AndroidX,因此您的專案可能不再需要 Jetifier 旗標。此外,該旗標也可能導致建構效能下降。看到這則警告後,您可以在版本分析器中執行檢查,確認能否移除該旗標。
支援測試固件
從 Android Studio Chipmunk Beta 1 開始,Android Studio 一併支援 Android 與 Java 測試固件。如要進一步瞭解測試固件功能,以及如何在 Java 專案中使用這類固件,請參閱 Gradle 的「使用測試固件」指南。
如要在 Android 程式庫模組中啟用測試固件,請將下列內容加入程式庫層級的 build.gradle
檔案:
android {
testFixtures {
enable true
// enable testFixtures's android resources (disabled by default)
// androidResources true
}
}
根據預設,發布程式庫時也會發布內含主要程式庫的測試固件 AAR。Gradle 模組中繼資料檔案將包含相關資訊,讓 Gradle 能夠在要求 testFixtures
元件時使用正確的成果。
如要停止在變化版本中發布程式庫的測試固件 AAR,請將下列內容加入程式庫層級的 build.gradle
檔案:
afterEvaluate {
components.release.withVariantsFromConfiguration(
configurations.releaseTestFixturesVariantReleaseApiPublication) { skip() }
components.release.withVariantsFromConfiguration(
configurations.releaseTestFixturesVariantReleaseRuntimePublication) { skip() }
}
如要運用已發布 Android 程式庫的測試固件 AAR,您可以使用 Gradle 的輔助方法 testFixtures()
。
dependencies {
testImplementation testFixtures('com.example.company:publishedLib:1.0')
}
根據預設,Lint 會分析測試固件來源。您可以將 Lint 設為忽略測試固件來源,方法如下:
android {
lint {
ignoreTestFixturesSources true
}
}
不支援重複的內容根目錄
從 AGP 7.2 開始,您無法再跨多個來源集共用同一個來源目錄。舉例來說,您無法同時對單元測試和檢測設備測試使用相同的測試來源。詳情請參閱「變更預設來源集設定」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["Android Gradle Plugin 7.2.0 (May 2022)\n\nAndroid Gradle plugin 7.2.0 is a major release that includes a variety of\nnew features and improvements. \n**7.2.2 (August 2022)**\n\nThis minor update corresponds to the release of Android Studio Chipmunk\nPatch 2 and includes the following bug fixes:\n\n- [Issue #232438924](https://issuetracker.google.com/issues/232438924): AndroidGradlePlugin version 7.2 breaks transform API when used along with ASM API\n- [Issue #231037948](https://issuetracker.google.com/issues/231037948): AGP 7.2.0-rc01 :buildSrc:generatePrecompiledScriptPluginAccessors - shadow/bundletool/com/android/prefs/AndroidLocation$AndroidLocationException\n\n**7.2.1 (May 2022)**\n\n\nThis minor update corresponds to the release of Android Studio Chipmunk\nPatch 1 and includes the following bug fixes:\n\n- [Issue #230361284](https://issuetracker.google.com/issues/230361284): bundletool does not package baseline profiles correctly\n\n\nTo see the other bug fixes included in this release, see the\n[Android Studio Chipmunk Patch 1\nrelease notes](/studio/releases#patch-releases).\n\nCompatibility\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| Gradle | 7.3.3 | 7.3.3 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). |\n| SDK Build Tools | 30.0.3 | 30.0.3 | [Install](/studio/intro/update#sdk-manager) or [configure](/tools/releases/build-tools) SDK Build Tools. |\n| NDK | N/A | 21.4.7075529 | [Install](/studio/projects/install-ndk#specific-version) or [configure](/studio/projects/install-ndk#apply-specific-version) a different version of the NDK. |\n| JDK | 11 | 11 | To learn more, see [setting the JDK version](/studio/intro/studio-config#jdk). |\n\nJetifier warning and check in Build Analyzer\n\nBuild Analyzer now displays a warning if your project's\n`gradle.properties` file includes\n`android.enableJetifier=true`. This flag was introduced in a\nprevious version of Android Studio to enable AndroidX for libraries that don't\nsupport AndroidX natively. However, the library ecosystem has mostly moved to\nsupport AndroidX natively and the Jetifier flag is probably no longer needed by\nyour project. Additionally, the flag can lead to slower build performance. If\nyou see this warning, you can run a check within Build Analyzer to confirm if\nthe flag can be removed.\n\nSupport for test fixtures\n\nStarting with Android Studio Chipmunk Beta 1, Android Studio supports both\nAndroid and Java test fixtures. See Gradle's guide on [using test fixtures](https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures){:.external}\nfor more information on the test fixtures feature and how to use it in a Java project.\n\nTo enable test fixtures in your Android library module, add the following to\nyour library-level `build.gradle` file: \n\n android {\n testFixtures {\n enable true\n // enable testFixtures's android resources (disabled by default)\n // androidResources true\n }\n }\n\nBy default, publishing your library also publishes the test fixtures AAR with\nthe main library. The Gradle Module Metadata file will contain information for\nGradle to be able to consume the right artifact when requesting the\n`testFixtures` component.\n\nTo disable publishing the test fixtures AAR of a library in the release variant,\nadd the following to your library-level `build.gradle` file: \n\n afterEvaluate {\n components.release.withVariantsFromConfiguration(\n configurations.releaseTestFixturesVariantReleaseApiPublication) { skip() }\n components.release.withVariantsFromConfiguration(\n configurations.releaseTestFixturesVariantReleaseRuntimePublication) { skip() }\n }\n\nTo consume the test fixtures AAR of a published Android library, you can use\nGradle's helper method `testFixtures()`. \n\n dependencies {\n testImplementation testFixtures('com.example.company:publishedLib:1.0')\n }\n\nBy default, lint will analyze test fixtures sources. You can configure\nlint to ignore test fixtures sources as follows: \n\n android {\n lint {\n ignoreTestFixturesSources true\n }\n }\n\nDuplicate content roots not supported\n\nStarting with AGP 7.2, you can no longer share the same source\ndirectory across multiple source sets. For example, you can't use the same\ntest sources for both unit tests and instrumentation tests. To learn more,\nsee [Change the\ndefault source sets configurations](/studio/build/build-variants#configure-sourcesets)."]]