返回提示词目录第 1299 页

升级安卓构建插件与工具链

核对安卓构建工具链兼容性,完成版本升级与配置迁移,并验证混淆发布构建和测试结果。

完整提示词

<context>
An Android Gradle Plugin upgrade is a build tooling change, separate from raising `targetSdk`, and it comes as a set: each AGP version needs a minimum Gradle version and JDK (AGP 8 needs JDK 17), and the Kotlin Gradle plugin, KSP and third-party Gradle plugins (Hilt, Google Services, Crashlytics, Compose) must support it. AGP 8 brought most of the breakage teams hit: `namespace` is required in each module's build file instead of the manifest `package` attribute; `BuildConfig` is no longer generated unless `buildFeatures.buildConfig` is on; R classes are non-transitive by default, so code referencing another module's resources through its own R breaks; the Transform API was removed; and R8 full mode is the default, which strips classes used only through reflection (Gson models, Retrofit interfaces, some serialization) and causes crashes only in release builds. Old DSL names (`compileSdkVersion`, `lintOptions`, `aaptOptions`) are deprecated or removed. AGP 9 brings another round, including built-in Kotlin support and removal of long-deprecated APIs; read its migration notes rather than assuming the AGP 8 list is complete. Android Studio's AGP Upgrade Assistant applies many of these steps and is worth running first. The Gradle wrapper should be updated with the wrapper task and a `distributionSha256Sum`. Debug builds passing proves little; the minified release build is where problems show.
</context>

<task>
Upgrade the Android Gradle Plugin to {{target_version}}.
{{#notes}}
Notes:
{{notes}}
{{/notes}}

1. Read `settings.gradle(.kts)`, the version catalog, root and module build files, `gradle-wrapper.properties`, `gradle.properties`, ProGuard or R8 rules and the CI config. Record AGP, Gradle, Kotlin, KSP and JDK versions.
2. From the AGP release notes, find the required Gradle and JDK versions for the target, and check each Gradle plugin and KSP for a compatible release. List blockers and stop for a decision on any.
3. Upgrade in this order on a branch: JDK in CI and toolchain config, Gradle wrapper (with checksum), then AGP, then Kotlin, KSP and other plugins as needed. Build after each step.
4. Fix the AGP changes that apply: add `namespace` per module, enable `buildConfig` only where used, fix cross-module R references, replace removed DSL and APIs, and move Transform-based plugins to their supported versions.
5. Build the minified release variant. If R8 full mode is now on, run the app's main flows on the release build and add keep rules for classes used through reflection, scoped as narrowly as possible, instead of turning full mode off.
6. Run unit and instrumented tests, lint, and compare APK or AAB size and the mapping file with the previous build. Note build time before and after.
</task>

<constraints>
- Do not change `targetSdk` or `compileSdk` behaviour in this change unless the new AGP requires a higher `compileSdk`; say so if it does.
- Do not disable R8 full mode or add broad `-keep class **` rules as the fix.
- Do not hide deprecation warnings with flags in `gradle.properties` without listing them as follow-ups.
- Only cite AGP changes confirmed in the release notes or seen failing.

{{> guardrails/verify-before-done}}
{{> guardrails/scope-discipline}}
</constraints>

<output_format>
## Starting point
AGP, Gradle, Kotlin, KSP, JDK versions; modules; plugins.
## Compatibility
Table: component, required version for the target, current, action.
## Changes made
By step: wrapper, AGP, plugins, build file and code changes, keep rules added.
## Verification
Debug and release builds, tests, lint, flows checked on the release build, size and build time comparison.
## Follow-ups
Deprecated flags left on, plugins waiting for releases.
</output_format>

可替换内容

  • {{target_version}}
  • {{#notes}}
  • {{notes}}
  • {{/notes}}
  • {{> guardrails/verify-before-done}}
  • {{> guardrails/scope-discipline}}

分类与标签

编程开发、安卓开发、构建升级、版本兼容、发布验证

前往 AI 图片创作