Skip to content

feat: agp v9 adoption#1006

Open
hurali97 wants to merge 2 commits into
react-native-community:mainfrom
hurali97:proposal/agp9-adoption
Open

feat: agp v9 adoption#1006
hurali97 wants to merge 2 commits into
react-native-community:mainfrom
hurali97:proposal/agp9-adoption

Conversation

@hurali97

@hurali97 hurali97 commented Jun 9, 2026

Copy link
Copy Markdown

Proposal: Android Gradle Plugin v9 Adoption

View the rendered RFC

@hurali97 hurali97 changed the title feat: add proposal for agp v9 adoption feat: agp v9 adoption Jun 9, 2026
Updated AGP v9 adoption proposal with changes for React Native core and community libraries, including Gradle upgrades and migration patterns.
Comment thread proposals/0000-android-agp-v9-adoption.md
@hurali97 hurali97 marked this pull request as ready for review June 10, 2026 14:54
@lukmccall

Copy link
Copy Markdown

The RFC looks great, thanks for putting it together! I've already started working on AGP9 support on the Expo side and opened a few PRs. Most things are working well, but I've hit a few unexpected issues that'll need more work. For instance, we have some custom Apollo client configuration in the dev-launcher that stopped working. I'll share more once I figure out how to fix it.

@lukmccall

Copy link
Copy Markdown

One random thought: what do you guys think about creating a kotlin-android-compat Gradle plugin that would apply kotlin-android conditionally based on the AGP version and whether the built-in Kotlin is enabled? It would make migration a bit easier for library authors, as most packages could then be compatible with both AGP 8 and 9.

@hurali97

Copy link
Copy Markdown
Author

One random thought: what do you guys think about creating a kotlin-android-compat Gradle plugin that would apply kotlin-android conditionally based on the AGP version and whether the built-in Kotlin is enabled? It would make migration a bit easier for library authors, as most packages could then be compatible with both AGP 8 and 9.

This sounds like a nice idea and could help with one part of the migration, but after thinking about it more, I’m not sure it would add enough value on its own.

Even with a kotlin-android-compat plugin, library authors would still need to handle a few manual migration steps:

  • Remove kotlin-android / org.jetbrains.kotlin.android from their build.gradle for AGP 9+, since built-in Kotlin replaces that plugin there.
  • Remove or migrate deprecated/removed APIs such as android.kotlinOptions and usages of .srcDirs where they are no longer valid.
  • Avoid configuring Kotlin-only sources through java.srcDirs.
  • Add AGP-version checks for the remaining compatibility differences anyway.

The custom plugin could dynamically apply kotlin-android for AGP < 9, which is useful. But it cannot really solve the case where the consuming project has already applied kotlin-android, because we can apply plugins programmatically, but we can’t safely “unapply” a plugin that was already applied by the build script.

So in practice, the plugin would cover only one part of the migration: conditionally applying kotlin-android for AGP 8 and below. The removal of kotlin-android for AGP 9+, plus the other DSL/source-set migrations, would still require manual changes from library authors. Because of that, I think the value might be relatively limited.

@lukmccall

lukmccall commented Jun 12, 2026

Copy link
Copy Markdown

Yes, I agree it won't solve every problem - realistically, this will still require some manual changes from library maintainers. But other changes, such as using kotlin.srcDirs instead of java.srcDirs, should work with both AGP versions. I'm only suggesting we add it to make supporting both possible in the majority of cases with minimal effort from the maintainer's perspective. The issue is that if you're using the plugins block, you can't apply plugins conditionally without falling back to the old apply plugin syntax - such a plugin would solve that.

@hurali97

hurali97 commented Jun 12, 2026

Copy link
Copy Markdown
Author

The issue is that if you're using the plugins block, you can't apply plugins conditionally without falling back to the old apply plugin syntax

True that. So If I catch it correctly, the library maintainers will need to replace the kotlin-android plugin with compat Gradle plugin?

For some libraries, this might be the only change that they need, for eg, react-native-pager-view. However, for majority the authors will need other manual adjustments.

I am also wondering whether to introduce a separate compat plugin OR we can add this as a fallback mechanism to RNGP? That way the library authors may not need to implement another plugin.

Nicola suggested that we can also think of separating library implementations from RNGP in a separate Gradle plugin, however that is optional for now and we will start that separately than AGP 9. I am mentioning it here because if we are able to add this compat mechanism to RNGP, we can later extract it out.

But other changes, such as using kotlin.srcDirs instead of java.srcDirs, should work with both AGP versions

Yes it should work, however there are a few catches. The kotlin-only sources can not be added to java.srcDirs, they should be added to kotlin.srcDirs, otherwise with built-in kotlin on AGP 9 there is a build crash. The .srcDirs is deprecated in favor of .directories with AGP v9, so in the future versions this maybe removed.

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.

3 participants