fix(android): restore namespace fallback for libraries not applying the React plugin#57290
Draft
cortinico wants to merge 2 commits into
Draft
fix(android): restore namespace fallback for libraries not applying the React plugin#57290cortinico wants to merge 2 commits into
cortinico wants to merge 2 commits into
Conversation
…he React plugin #57038 narrowed configureNamespaceForLibraries from a rootProject-wide sweep to only the project applying `com.facebook.react`. That was necessary because the old code re-ran the sweep from every library, and AGP 9 errors when `finalizeDsl` is registered after a project's DSL has been finalized. The narrowing has a side effect: third-party Android libraries that do NOT apply `com.facebook.react` and still rely on the manifest `package` attribute (e.g. older react-native-linear-gradient) no longer receive a namespace, so they fail under AGP 9 with "Namespace not specified". Restore the broad coverage by sweeping all `com.android.library` subprojects once, from the application project (which applies the plugin a single time, avoiding the repeated-traversal finalizeDsl error from #57038). Guard configureNamespaceForLibraries so it registers its finalizeDsl callback at most once per project, since libraries that DO apply the React plugin are now reachable from both the per-library hook and the app-level sweep.
The app-level namespace sweep registered a `finalizeDsl` callback on every
`com.android.library` subproject. In composite/monorepo builds (e.g. rn-tester,
where ReactAndroid is a sibling library) some library projects are already
evaluated — and their AGP DSL already finalized — by the time the app applies
the sweep, so registering `finalizeDsl` on them fails on AGP 9 with
"It is too late to call finalizeDsl".
Guard the sweep with `!subproject.state.executed`: only configure projects that
haven't been evaluated yet (for which `finalizeDsl` is still valid). In a regular
app build the app is evaluated before its libraries (ReactRootProjectPlugin's
`evaluationDependsOn(":app")`), so all libraries are still pending and covered.
Already-evaluated projects in monorepo builds define their own namespace, so
skipping them is safe.
Verified against rn-tester: `:packages:rn-tester:android:app:assembleDebug
--dry-run` reproduces the crash without this guard and succeeds with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
#57038 narrowed configureNamespaceForLibraries from a rootProject-wide sweep to only the project applying
com.facebook.react. That was necessary because the old code re-ran the sweep from every library, and AGP 9 errors whenfinalizeDslis registered after a project's DSL has been finalized.The narrowing has a side effect: third-party Android libraries that do NOT apply
com.facebook.reactand still rely on the manifestpackageattribute (e.g. older react-native-linear-gradient) no longer receive a namespace, so they fail under AGP 9 with "Namespace not specified".Restore the broad coverage by sweeping all
com.android.librarysubprojects once, from the application project (which applies the plugin a single time, avoiding the repeated-traversal finalizeDsl error from #57038). Guard configureNamespaceForLibraries so it registers its finalizeDsl callback at most once per project, since libraries that DO apply the React plugin are now reachable from both the per-library hook and the app-level sweep.Changelog:
[INTERNAL] - restore namespace fallback for libraries not applying the React plugin
Test Plan:
CI