Skip to content

fix(cli): remove AGP 9 property shims and jcenter() in cap migrate - #8584

Draft
andredestro wants to merge 1 commit into
nextfrom
fix/RMET-5370/cap-migrate-agp9-gradle9
Draft

fix(cli): remove AGP 9 property shims and jcenter() in cap migrate#8584
andredestro wants to merge 1 commit into
nextfrom
fix/RMET-5370/cap-migrate-agp9-gradle9

Conversation

@andredestro

Copy link
Copy Markdown
Contributor

Description

Extends cap migrate with two Android cleanup steps that Gradle 9 / AGP 9 make necessary:

  1. gradle.properties: removes the 10 compatibility flags that Android Studio's AGP Upgrade Assistant writes to preserve the AGP 8 defaults. android.useAndroidX=true is kept.
  2. jcenter(): removes it from android/build.gradle and android/app/build.gradle, and makes sure the repositories block it lived in declares mavenCentral().

Both steps run before the gradle wrapper upgrade. The wrapper task runs on Gradle 9.5.1 the second time around, so a leftover jcenter() would fail it at the configuration phase and the wrapper upgrade would be lost.

Unlike the Capacitor 3 -> 4 migrator, the jcenter() removal is no longer opt-in, and it only touches repositories blocks that actually contain jcenter(), so the nested flatDir block in a Capacitor 8 app/build.gradle is left alone.

Adds cli/test/migrate-android-gradle.spec.ts: 19 tests covering the transformations and a block that runs them against a project on disk.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

Users have been running the AGP 9 migration in Android Studio while still on Capacitor 8. The Assistant injects flags that a Capacitor app does not need: most are deprecated and will be removed in AGP 10, and a couple break a Capacitor 9 build (android.builtInKotlin=false disables the Kotlin support AGP 9 now bundles, android.sdk.defaultTargetSdkToCompileSdkIfUnset=false stops AGP from inferring targetSdkVersion).

RepositoryHandler.jcenter() was removed in Gradle 9.0. Any build.gradle that still calls it fails immediately at the configuration phase with Could not find method jcenter().

Platforms Affected

  • Android
  • iOS
  • Web

Android Studio's AGP Upgrade Assistant writes a set of compatibility flags
into gradle.properties to keep the AGP 8 defaults. A Capacitor app needs
none of them: most are deprecated and will be removed in AGP 10, and a
couple break a Capacitor 9 build (android.builtInKotlin=false disables the
Kotlin support AGP 9 bundles). Strip them during migration.

Gradle 9 also removed jcenter(), which fails at the configuration phase,
so drop it from the root and app build.gradle and make sure the block it
lived in declares mavenCentral().

Both steps run before the gradle wrapper upgrade: the wrapper task runs on
Gradle 9.5.1 the second time around, so a leftover jcenter() would fail it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant