Description
Description
Hello React Native team,
Under certain conditions, a vanilla React Native CLI app will always crash on startup, as soon as its MainApplication
runs on React Native 0.80.0
.
Namely, the error detailed just below is being thrown every single time regardless of whether it's a release/debug build. After some digging, I found that the offending line is this one here. However, despite how it seems the actual issue is not in one of the core RN modules.
After running the following short snippet:
val packages = PackageList(this@MainApplication).packages
for (pkg in packages) {
if (pkg is ViewManagerOnDemandReactPackage) {
Log.d("ViewManagerCheck", "👀 Found ViewManager package: ${pkg.javaClass.name}")
}
}
in onCreate()
within MainApplication.kt
, I managed to comb the issue down to a couple of view managers that stemmed from external libraries (react-native-gesture-handler
, react-native-svg
and @react-native-camera-roll/camera-roll
). The real culprit (in the repository I work on) turned out to be @react-native-camera-roll/camera-roll
, because it does this, which will always result in a crash before anything else can happen in the app.
Combing through the 0.80.0
PRs, I believe that this one is the one that introduced this regression during the port of ReactInstance
from Java
to Kotlin
. If we look at the old implementation, we can see that there's a null
check in place which prevented this from happening, whereas the new one does not.
Of course, @react-native-camera-roll/camera-roll
is just an example that I managed to encounter - I'm sure many other libraries who possibly return null
will also cause any React Native app using them to crash on startup. I used it in the reproducer just as an example and I'll open a PR/issue on @react-native-camera-roll/camera-roll
a bit later, but I believe that this might need to be addressed upstream as well.
Steps to reproduce
git clone https://github.com/isekovanic/rn-0.80.0-android-crash-reproducer.git
cd rn-0.80.0-android-crash-reproducer/ReproducerApp
yarn install
yarn run android --list-devices
(and select your device/emulator)
React Native Version
0.80.0
Affected Platforms
Runtime - Android
Output of npx @react-native-community/cli info
System:
OS: macOS 15.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 173.17 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 22.13.1
path: ~/.nvm/versions/node/v22.13.1/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 8.19.4
path: ~/Projects/stream-chat-react-native/node_modules/.bin/npm
Watchman:
version: 2024.08.12.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK: Not Found
IDEs:
Android Studio: 2024.3 AI-243.26053.27.2432.13536105
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.12
path: /usr/bin/javac
Ruby:
version: 3.3.4
path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 19.0.0
wanted: 19.0.0
react:
installed: 19.1.0
wanted: 19.1.0
react-native:
installed: 0.80.0
wanted: ^0.80.0
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
[runtime not ready]: Error: Exception in HostFunction: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.Collection.iterator()' on a null object reference
at java.util.AbstractCollection.addAll(AbstractCollection.java:335)
at com.facebook.react.runtime.ReactInstance$BridgelessViewManagerResolver.getLazyViewManagerNames(ReactInstance.kt:547)
at com.facebook.react.runtime.ReactInstance._init_$lambda$2(ReactInstance.kt:228)
at com.facebook.react.runtime.ReactInstance.$r8$lambda$kHxgB1VvaqAOBtRVp4CgY0gnLGo(Unknown Source:0)
at com.facebook.react.runtime.ReactInstance$$ExternalSyntheticLambda3.getConstants(D8$$SyntheticClass:0)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.kt:21)
at android.os.Looper.loopOnce(Looper.java:249)
at android.os.Looper.loop(Looper.java:337)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$1(MessageQueueThreadImpl.kt:175)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.$r8$lambda$ldnZnqelhYFctGaUKkOKYj5rxo4(Unknown Source:0)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
at java.lang.Thread.run(Thread.java:1012)
, js engine: hermes
MANDATORY Reproducer
https://github.com/isekovanic/rn-0.80.0-android-crash-reproducer