使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android Gradle 插件 7.2.0(2022 年 5 月)
Android Gradle 插件 7.2.0 是一个主要版本,包含各种新功能和改进。
7.2.2(2022 年 8 月)
本次要更新对应于 Android Studio Chipmunk 补丁 2,并包含以下 bug 修复:
- 问题 232438924:与 ASM API 一起使用时,AndroidGradlePlugin 版本 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,并包含以下 bug 修复:
如需查看此版本中包含的其他 bug 修复,请参阅 Android Studio Chipmunk 补丁 1 版本说明。
兼容性
|
最低版本 |
默认版本 |
备注 |
Gradle |
7.3.3 |
7.3.3 |
如需了解详情,请参阅更新 Gradle。 |
SDK Build Tools |
30.0.3 |
30.0.3 |
安装或配置 SDK Build Tools。 |
NDK |
不适用 |
21.4.7075529 |
安装或配置其他版本的 NDK。 |
JDK |
11 |
11 |
如需了解详情,请参阅设置 JDK 版本。 |
Build Analyzer 中的 Jetifier 警告和检查
现在,如果项目的 gradle.properties
文件包含 android.enableJetifier=true
,Build Analyzer 会显示警告。该标志是在之前的 Android Studio 版本中引入的,旨在为不能原生支持 AndroidX 的库启用 AndroidX。不过,库生态系统大多已经变为能够原生支持 AndroidX,因此您的项目可能不再需要 Jetifier 标志了。此外,该标志可能会降低 build 性能。如果您看到此警告,可在 Build Analyzer 中运行检查,以确认能否移除该标志。
支持测试固件
从 Android Studio Chipmunk Beta 1 开始,Android Studio 支持 Android 和 Java 测试固件。如需详细了解测试固件功能以及如何在 Java 项目中使用该功能,请参阅与如何使用测试固件{:.external}相关的 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 和/或其关联公司的注册商标。
最后更新时间 (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,["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)."]]