feat: adopt AGP v9#57038
Conversation
| androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } | ||
| androidx-appcompat-resources = { module = "androidx.appcompat:appcompat-resources", version.ref = "androidx-appcompat" } | ||
| androidx-autofill = { module = "androidx.autofill:autofill", version.ref = "androidx-autofill" } | ||
| androidx-collection = { module = "androidx.collection:collection", version.ref = "androidx-collection" } |
| tasks.withType<JavaCompile>().configureEach { | ||
| exclude("com/facebook/react/processing/**") | ||
| exclude("com/facebook/react/module/processing/**") | ||
| } |
There was a problem hiding this comment.
Why this? This should not be necessary at all
There was a problem hiding this comment.
I think it is required with AGP9 as we face the following error that states unavailability of excludes filter. I believe this happened as part of: https://issuetracker.google.com/issues/368609737
There was a problem hiding this comment.
Ah I see. You can remove those as those folders no longer exist
| # Those 2 properties are needed to make our project compatible with | ||
| # AGP 9.0.0 for the time being. Ideally we should not opt-out of | ||
| # builtInKotlin and newDsl once AGP 9.0.0 hits stable. | ||
| # More on this: https://developer.android.com/build/releases/agp-preview#android-gradle-plugin-built-in-kotlin | ||
| android.builtInKotlin=false | ||
| android.newDsl=false |
There was a problem hiding this comment.
Are we good removing those?
There was a problem hiding this comment.
I believe so. After removing those and bumping to AGP v9.2.1 - there were build issues that have already been fixed as part of this PR, so we should be good.
| tasks.withType<JavaCompile>().configureEach { | ||
| exclude("com/facebook/react/processing/**") | ||
| exclude("com/facebook/react/module/processing/**") | ||
| } |
There was a problem hiding this comment.
Ah I see. You can remove those as those folders no longer exist
| # Those 2 properties are needed to make our project compatible with | ||
| # AGP 9.0.0 for the time being. Ideally we should not opt-out of | ||
| # builtInKotlin and newDsl once AGP 9.0.0 hits stable. | ||
| # More on this: https://developer.android.com/build/releases/agp-preview#android-gradle-plugin-built-in-kotlin | ||
| android.builtInKotlin=false | ||
| android.newDsl=false |
| android.builtInKotlin=false | ||
| android.newDsl=false No newline at end of file |
There was a problem hiding this comment.
Enabling the opt-outs for hello-world to match the behavior of template
|
The failing runs for community template:
Should be fixed once react-native-community/template#224 is merged |
|
@cortinico has imported this pull request. If you are a Meta employee, you can view this in D107656378. |

Summary:
This PR is part of Android Gradle Plugin v9 adoption. With this PR, we adopt the AGP9 repository wide and address the deprecated APIs with the newer ones.
This is in combination with #57038
Changes to `configureBuildConfigFieldsForLibraries` and `configureNamespaceForLibraries`
These helpers are called from `ReactPlugin.apply`, but they currently iterate over `rootProject.allprojects`. Since `com.facebook.react` is applied by multiple Android library projects, each application of the plugin repeats the same traversal and attempts to register `finalizeDsl` callbacks for every Android library project.
The first traversal can register the callbacks successfully. However, a later traversal can reach a project whose Android DSL finalization phase has already completed. Starting with AGP 9, AGP explicitly errors when
finalizeDslis called after that phase has passed, which causes the build failure. seeTo understand this, consider following modules:
The current code on main, would result in executing the following block 3 times:
The output would be:
Now with AGP9, the same code will throw this error:
Solution:
Since these helpers are only intended to configure Android library projects that apply the React plugin, we can configure the current project inside
pluginManager.withPlugin("com.android.library")instead of repeatedly configuring all projects from every plugin application.One important note for
configureNamespaceForLibrariesis that the oldcom.android.build.gradle.LibraryExtensionis deprecated in favor ofcom.android.build.api.dsl.LibraryExtension- which does not exposemanifestFilefrom thesourceSets. So we have to define a path for it. For most libraries, this should be OK but for the ones which define custom path, this will fail.Hence, I believe, if it's important to have this fallback, we take this tradeoff. Otherwise, since there has been 2 years passed for AGP8 adoption and the time when this fallback was added, we may safely remove this function as almost all libraries now define a
namespaceinandroid { }DSL.With the above in place, we make one final change and that is to move these two functions inside the
withPlugin("com.android.library")as these are only intended for libraries and that way, we also ensure that these will only be applied once thecom.android.libraryplugin has been applied.Changelog:
[ANDROID] [BREAKING] - Adopt AGP v9
Test Plan:
rn-tester.mp4