Fix Android release APK crash: enable new architecture for RN 0.84#618
Fix Android release APK crash: enable new architecture for RN 0.84#618
Conversation
There was a problem hiding this comment.
Pull request overview
Enables React Native’s new architecture by default for the Android example app (required for RN 0.84’s bridgeless/new-arch initialization paths), while keeping Detox Android E2E builds on the old architecture via a Gradle property override to avoid known incompatibilities.
Changes:
- Set
newArchEnabled=trueinexample/android/gradle.properties. - Update Detox Android build command to pass
-PnewArchEnabled=falsewhen assembling APKs for E2E.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| example/android/gradle.properties | Switches the example app’s default Android build to the new architecture. |
| example/.detoxrc.js | Forces old-arch builds for Detox by overriding newArchEnabled at build time. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # your application. You should enable this flag either if you want | ||
| # to write custom TurboModules/Fabric components OR use libraries that | ||
| # are providing them. | ||
| # Temporarily disabled for Detox E2E testing compatibility | ||
| newArchEnabled=false | ||
| newArchEnabled=true |
There was a problem hiding this comment.
The surrounding docs still state that Android Detox runs with newArchEnabled=false set in the example app (e.g. example/e2e/README.md and CLAUDE.md). Since the default is now true and Detox is handled via a Gradle CLI override, consider updating the comment here to reflect the new behavior (and update those docs in the same PR) to avoid confusing contributors.
The release APK was crashing with "TurboModuleRegistry.getEnforcing(...):
'PlatformConstants' could not be found" because:
1. newArchEnabled was false while MainApplication.kt uses bridgeless APIs
(loadReactNative, getDefaultReactHost). RN 0.84 requires new arch for
CoreReactPackage which provides PlatformConstants.
2. The JS spec eagerly called TurboModuleRegistry.getEnforcing at module
load time and used an outdated isTurboModuleEnabled check based on
global.__turboModuleProxy (always true in bridgeless mode).
3. Top-level Platform.OS access in index.tsx forced eager loading of
NativePlatformConstantsAndroid which calls getEnforcing('PlatformConstants').
Fixes:
- Enable newArchEnabled=true in gradle.properties (default for RN 0.84)
- Modernize TurboModule spec: use TurboModuleRegistry.get() instead of
manual isTurboModuleEnabled check with getEnforcing (follows pattern
used by react-native-safe-area-context and other maintained libraries)
- Move Platform.OS access from module top-level into validateOptions()
to defer native module loading until first use
- Pass -PnewArchEnabled=false only for Detox Android builds
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ff3c9f1 to
e16f546
Compare
Summary
newArchEnabled=trueingradle.properties— required for RN 0.84 which uses bridgeless/new-arch APIs inMainApplication.kt-PnewArchEnabled=falseonly for Detox Android builds (old arch compatibility)TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be foundcrash on release APKTest plan
🤖 Generated with Claude Code