Repository navigation
Conversation
`configureJavaToolChains` runs for each application that applies the
React plugin and registers a `finalizeDsl` callback on every Android
project in the build. AGP finalizes a project's DSL when the project is
evaluated, and AGP 9 fails the build when `finalizeDsl` is called after
that:
It is too late to call `finalizeDsl` as the DSL finalization
blocks have already been executed.
So the build fails during configuration when Gradle evaluates a library
before the app, and when a second app applies the plugin after the
first has been evaluated. `ReactRootProjectPlugin` orders `:app` before
every other project, so the first case needs a build that does not
apply that plugin, or whose React app is not `:app`.
Skip projects that are already evaluated, as the namespace fallback in
`ReactPlugin` already does. A library evaluated before the app keeps
the Java version it declares.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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:
JdkConfiguratorUtils.configureJavaToolChainsruns for each application that applies the React plugin, and registers afinalizeDslcallback on every Android project in the build to set Java 17. AGP finalizes a project's DSL when the project is evaluated, and AGP 9 fails the build whenfinalizeDslis called after that:So the build fails during configuration in two cases:
ReactRootProjectPluginmakes every other project depend on the evaluation of:app, so this needs a build that does not apply that plugin, or one in which the app that applies the React plugin is not the:appproject.ReactPluginalready skips evaluated projects for the same reason when it applies the namespace fallback to libraries (#57290). This change does the same inconfigureJavaToolChains. A library that is evaluated before the app keeps the Java version it declares.Changelog:
[ANDROID] [FIXED] - Fix "It is too late to call
finalizeDsl" when a library is evaluated before the app or a build has two appsTest Plan:
JdkConfiguratorUtilsTest(new) builds projects withProjectBuilder, applies the Android plugins, and evaluates them:configureJavaToolChains_withALibraryEvaluatedBeforeTheApp_alignsTheAppconfigureJavaToolChains_withTwoApps_alignsBothupstream/main94aee19ac9with only the new test file: both tests fail with thefinalizeDslerror above, thrown fromJdkConfiguratorUtils.configureJavaToolChains.[11, 11]instead of 17), so the tests do check that the versions are set.Also run: ktfmt
--dry-run --set-exit-if-changedon the two changed Kotlin files (clean),git diff --check(clean).Not run: the rest of the plugin's tests, and a real Android build in either failing layout.
🤖 Generated with Claude Code