Skip to content

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

Open
andredestro wants to merge 2 commits into
nextfrom
fix/RMET-5370/cap-migrate-agp9-gradle9
Open

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

Conversation

@andredestro

@andredestro andredestro commented Aug 28, 2026

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.

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.

mavenCentral() is not added back, and android/app/build.gradle is not scanned, per review feedback: the 3 -> 4 migrator always added mavenCentral() regardless of the opt-in jcenter() removal, it has been in the template since Capacitor 4, and jcenter() has only ever been in the root build.gradle of the templates.

Adds cli/test/migrate-android-gradle.spec.ts: 15 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.
@jcesarmobile

Copy link
Copy Markdown
Member

I don't think migrate command should add mavenCentral(), it was already added in the 3 to 4 migrator, the deletion of jcenter() was optional, but the addition of mavenCentral() was always done, so we could assume all apps have it.

jcenter() has never been in android/app/build.gradle in our templates, only in android/build.gradle, so I don't think we should worry about that neither.

Do not add mavenCentral() back. The 3 to 4 migrator always added it
regardless of the opt-in jcenter() removal, and it has been in the template
since Capacitor 4, so every app is assumed to declare it already.

Also stop scanning app/build.gradle: jcenter() has only ever been in the
root build.gradle of the templates.

Removes the repositories block scanning that only existed to place the
mavenCentral() insertion.
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.

2 participants