$npx -y skills add hanamizuki/solopreneur --skill agp-9-upgradeUpgrades, or migrates, an Android project to use Android Gradle Plugin
| 1 | ## Migration guide |
| 2 | |
| 3 | See the [AGP 9 migration guide](references/android/build/releases/agp-9-0-0-release-notes.md) for the major changes, many |
| 4 | breaking, in AGP 9 compared to AGP 8. |
| 5 | |
| 6 | ## Requirements |
| 7 | |
| 8 | If the user requests to update or migrate to AGP 9, first check the AGP version |
| 9 | used in the project. If it is lower than 9, stop and ask the user to run the AGP |
| 10 | Upgrade Assistant in Android Studio to update to the latest stable version of |
| 11 | AGP, and confirm when done. The user may also request that this requirement be |
| 12 | skipped; if this is the case, you should update the version of AGP to the latest |
| 13 | stable version as part of the AGP 9 migration. See the |
| 14 | [AGP 9 migration guide](references/android/build/releases/agp-9-0-0-release-notes.md) for how to do this. |
| 15 | |
| 16 | Each version of AGP has its own set of compatibilities with other tools, such as |
| 17 | Gradle, JDK, and Kotlin. The release notes for each of these versions will |
| 18 | include a **Compatibility** table indicating the minimum versions for these |
| 19 | tools. |
| 20 | |
| 21 | Do not use this skill for KMP projects, as they are unsupported. |
| 22 | |
| 23 | ## Steps |
| 24 | |
| 25 | If AGP is already at 9 or higher, then do the following: |
| 26 | |
| 27 | ### Step 1: Update dependencies |
| 28 | |
| 29 | If KSP (`com.google.devtools.ksp`) is used in the project, ensure it is on |
| 30 | version 2.3.6 or higher. |
| 31 | |
| 32 | If Hilt is used in the project, ensure it is on version 2.59.2 or higher. |
| 33 | |
| 34 | ### Step 2: Migrate to built-in Kotlin |
| 35 | |
| 36 | See [the guide](references/android/build/migrate-to-built-in-kotlin.md) for detailed information. |
| 37 | |
| 38 | ### Step 3. Migrate to the new AGP DSL |
| 39 | |
| 40 | See [the guide](references/android/build/releases/agp-9-0-0-release-notes.md) for detailed information. |
| 41 | |
| 42 | See also [gradle-recipes](references/recipes.md) for examples on how to migrate old code to code |
| 43 | that is compatible with AGP 9 and the new DSL. |
| 44 | |
| 45 | ### Step 4. Migrate kapt to KSP or legacy-kapt |
| 46 | |
| 47 | If KSP (`com.google.devtools.ksp`) or kapt (`org.jetbrains.kotlin.kapt`) are |
| 48 | used in the project, see [KSP, kapt, and legacy-kapt](references/ksp-kapt.md) for detailed migration |
| 49 | steps. |
| 50 | |
| 51 | ### Step 5. BuildConfig |
| 52 | |
| 53 | If any Android module contains custom BuildConfig fields, see [BuildConfig](references/buildconfig.md) |
| 54 | for detailed information. |
| 55 | |
| 56 | ### Step 6. Update gradle.properties |
| 57 | |
| 58 | After the migration, check gradle.properties. Remove the following flags: |
| 59 | |
| 60 | 1. android.builtInKotlin |
| 61 | 2. android.newDsl |
| 62 | 3. android.uniquePackageNames |
| 63 | 4. android.enableAppCompileTimeRClass |
| 64 | |
| 65 | Additionally, delete all temporary files you've created. |
| 66 | |
| 67 | ## Guidelines |
| 68 | |
| 69 | - Never write or run python scripts. |
| 70 | - Only search the Gradle dependency cache when inspecting external dependencies, and only as a last resort. |
| 71 | - Never add `android.disallowKotlinSourceSets=false` to `gradle.properties`. |
| 72 | - When verifying changes, don't run the `clean` task. This is a waste of time. |
| 73 | |
| 74 | ## Verification |
| 75 | |
| 76 | After migration, verify the following: |
| 77 | |
| 78 | 1. Gradle IDE sync succeeds. |
| 79 | 2. `./gradlew help` succeeds. |
| 80 | 3. `./gradlew build --dry-run` succeeds. |
| 81 | |
| 82 | ## Troubleshooting |
| 83 | |
| 84 | Paparazzi v2.0.0-alpha04 and lower versions have issues with AGP 9. See |
| 85 | [references/paparazzi-gradle-9.md](references/paparazzi-gradle-9.md) for details. |