fix(android): detect newArchEnabled at subproject scope#1037
Open
jmalmo wants to merge 1 commit into
Open
Conversation
`isNewArchitectureEnabled()` reads `rootProject.hasProperty("newArchEnabled")`.
On RN >= 0.82 with Expo SDK 55 the new architecture is mandatory and the
property is no longer required to live in `android/gradle.properties`;
React Native's `ReactRootProjectPlugin` instead sets `newArchEnabled=true`
on each subproject's `extraProperties`. The rootProject-scoped check
therefore returns false in that scenario, the library skips
`apply plugin: "com.facebook.react"`, no codegen tasks register, and the
consumer build fails at `:app:configureCMakeDebug` referencing the
missing `node_modules/react-native-mmkv/android/build/generated/source/codegen/jni/`.
Switch the helper to `project.hasProperty("newArchEnabled")`. That
covers both the RN >= 0.82 path (subproject extraProperties) and the
legacy explicit-opt-in path (`gradle.properties` values propagate to
every project), without dropping legacy-arch support.
Same fix and rationale as mrousavy/nitro#1314, applied to mmkv's own
build.gradle which carries an independent copy of the gate from
Nitrogen's `packages/template` at bootstrap time.
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.
What I changed
I switched
isNewArchitectureEnabled()inpackages/react-native-mmkv/android/build.gradlefromrootProject.hasProperty(...)toproject.hasProperty(...). One-line diff.Why
Same root cause as mrousavy/nitro#1314, which I opened earlier today.
react-native-mmkvcarries its own copy of the gate (line 18) — it was copied from Nitrogen'spackages/template/android/build.gradleat bootstrap time, not regenerated by Nitrogen on each build, so the nitro PR's fix to the template doesn't reach already-published consumers of mmkv. This PR closes the gap on mmkv specifically.I hit this on a fresh React Native 0.83 / Expo SDK 55 dev-client app with
react-native-mmkv@^4andreact-native-nitro-modulesinstalled.bun androidfailed at:app:configureCMakeDebug[arm64-v8a]:After digging in: on RN >= 0.82 the new architecture is mandatory and
newArchEnabledis no longer required to live ingradle.properties. React Native'sReactRootProjectPlugininstead sets the property on each subproject'sextraProperties. The current rootProject-scoped check misses that path — the lib silently skipsapply plugin: "com.facebook.react", no codegen tasks register, and the consumer build dies during CMake configure. The same trap fires after a stale, non---cleanExpo prebuild wheregradle.propertiesstays put and never picks up the new template's content.project.hasProperty(...)covers both paths without dropping legacy-arch support:ReactRootProjectPlugin's subprojectextraProperties.gradle.propertiesvalues propagate to every project, soproject.hasProperty(...)still returnstrue.Test plan
I considered pinning the regression by removing
newArchEnabled=truefromexample/android/gradle.properties(the same approach I used in mrousavy/nitro#1314). However,react-native-mmkvdepends onreact-native-nitro-modules@0.35.6from npm, which still carries the un-fixed legacy gate at the same line. Without the property ingradle.properties, the example app fails at:app:configureCMakeDebugbecause of nitro's missing codegen, not mmkv's — verified locally:So the regression-pin test will only become viable once nitro PR #1314 ships in a tagged release and mmkv bumps the dep. I'd be happy to send a follow-up PR removing the property at that point.
What I did verify locally with the property restored (i.e. the current PR state):
Result:
BUILD SUCCESSFUL in 44s.:react-native-mmkv:generateCodegenArtifactsFromSchemaran,:react-native-mmkv:configureCMakeDebug[arm64-v8a]succeeded, and the example app built end-to-end. The fix doesn't regress the green path.Other checks:
bun install— green.bun typecheck— green.bun lint— green.bun run test— 4 / 4 Jest specs pass.nitrogenregen needed (gradle-only change;run-nitrogen.ymldoesn't trigger on**/*.gradle*paths).Notes
main. No nitrogen output changes, no spec/test removals, no unrelated edits.