Community编程与开发github.com

lerchenflo/claudeskills

将 Android 项目升级或迁移至 Android Gradle Plugin (AGP) 版本 9。不适用于 Kotlin Multiplatform (KMP) 项目。

claudeskills 是什么?

此技能旨在帮助开发者将 Android 项目迁移至 Android Gradle Plugin (AGP) 版本 9。它提供了从版本检查、依赖更新到配置迁移的完整步骤指导,确保项目基于 AGP 9 的最新特性进行升级。该技能支持在 Claude Code、Cursor 等 AI Agent 平台中通过读取项目文件并按照预定义的步骤自动执行迁移任务。主要步骤包括:检查 AGP 版本并确保已更新至最新稳定版、更新 KSP 和 Hilt 依赖、迁移到内置 Kotlin、迁移至新的 AGP DSL、将 kapt 替换为 KSP 或 legacy-kapt、处理 BuildConfig 字段以及清理 gradle.properties 中的废弃标志。它还包含了验证步骤和针对 Paparazzi 等第三方库的已知问题的处理。请注意,此技能专为纯 Android 项目设计,明确不支持 Kotlin Multiplatform (KMP) 项目。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lerchenflo/claudeskills/tree/HEAD/android/agp-9-upgrade

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

迁移指南

请参阅 AGP 9 迁移指南 了解从 AGP 8 升级到 AGP 9 的重大变更(其中许多具有破坏性)。

前提条件

如果用户请求更新或迁移到 AGP 9,请首先检查项目中使用的 AGP 版本。如果低于 9,请停止并要求用户在 Android Studio 中运行 AGP 升级助手以更新到最新的稳定版 AGP,并在完成后确认。用户也可能要求跳过此前提条件;如果是这样,您应在 AGP 9 迁移过程中将 AGP 版本更新为最新的稳定版。请参阅 AGP 9 迁移指南 了解具体操作方法。

每个 AGP 版本都有自己的工具兼容性要求,例如 Gradle、JDK 和 Kotlin。每个版本的发布说明中都包含一个“兼容性”表格,列出了这些工具的最低版本要求。

请勿将本技能用于 KMP 项目,因为此类项目不受支持。

步骤

如果 AGP 已经是 9 或更高版本,请执行以下操作:

步骤 1:更新依赖

如果项目中使用 KSP (com.google.devtools.ksp),请确保其版本为 2.3.6 或更高。

如果项目中使用 Hilt,请确保其版本为 2.59.2 或更高。

步骤 2:迁移到内置 Kotlin

请参阅指南以获取详细信息。

步骤 3:迁移到新的 AGP DSL

请参阅指南以获取详细信息。

另请参阅 gradle-recipes 获取如何将旧代码迁移到兼容 AGP 9 和新 DSL 的代码示例。

步骤 4:将 kapt 迁移到 KSP 或 legacy-kapt

如果项目中使用了 KSP (com.google.devtools.ksp) 或 kapt (org.jetbrains.kotlin.kapt),请参阅 KSP、kapt 和 legacy-kapt 了解详细的迁移步骤。

步骤 5:BuildConfig

如果任何 Android 模块包含自定义的 BuildConfig 字段,请参阅 BuildConfig 以获取详细信息。

步骤 6:更新 gradle.properties

迁移完成后,请检查 gradle.properties。移除以下标志:

  1. android.builtInKotlin
  2. android.newDsl
  3. android.uniquePackageNames
  4. android.enableAppCompileTimeRClass

此外,删除您创建的所有临时文件。

指导原则

  • 不要编写或运行 Python 脚本。
  • 仅在检查外部依赖项且万不得已时搜索 Gradle 依赖项缓存。
  • 切勿向 gradle.properties 中添加 android.disallowKotlinSourceSets=false。
  • 在验证更改时,不要运行 clean 任务。这是浪费时间。

验证

迁移后,请验证以下内容:

  1. Gradle IDE 同步成功。
  2. ./gradlew help 成功。
  3. ./gradlew build --dry-run 成功。

故障排除

Paparazzi v2.0.0-alpha04 及更低版本与 AGP 9 存在兼容性问题。有关详细信息,请参阅 references/paparazzi-gradle-9.md。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

lerchenflo/claudeskills

Provides instructions for installing and using the `android` CLI. The `android` command-line tool is a critical tool for Android development and helps you create new Android projects, run Android apps on devices, manage and interact with Android virtual devices (including screenshots and UI inspection), manage Android SDK components, look up official Android documentation, and discover and install official Android skills.

lerchenflo/claudeskills

Manages Android performance profiling and debugging. Triggers when the user asks to record or analyze Android performance data, such as system traces, heap dumps, method recordings, callstack samples, memory allocations, or investigate bottlenecks, jank, memory leaks, and app startup issues on Android, or when the user asks to write, debug, or execute ad-hoc SQL queries. Applies to both user and system apps or services.

lerchenflo/claudeskills

Analyzes Android apps to identify key user workflows for AppFunctions such as creating a note, playing media, or sending an automated or AI agent triggered message, voice commands, or system shortcuts, without needing to open the app UI. Generates Kotlin code to expose these workflows to the Android system, allowing agents to discover and execute them on-device. Also refines KDoc documentation to ensure AI agents correctly understand and use the provided functionality.

lerchenflo/claudeskills

Use this skill to migrate your Jetpack Compose app to add adaptive edge-to-edge support and troubleshoot common issues. Use this skill to fix UI components (like buttons or lists) that are obscured by or overlapping with the navigation bar or status bar, fix IME insets, and fix system bar legibility.

相关技能