App freezes on startup after adding custom native module #48944
Labels
Needs: Author Feedback
Needs: Repro
This issue could be improved with a clear list of steps to reproduce the issue.
Description
After adding a custom native module to my React Native app, the app freezes on startup and never loads the main screen. I followed the documentation for creating a native module and linked it properly, but after that, the app simply hangs on the splash screen and does not proceed.
I’ve tried cleaning the build, resetting the cache, and running the app on different devices, but the issue persists.
Expected Behavior:
The app should start normally and load the main screen even after adding the custom native module.
Steps to Reproduce:
Create a custom native module following the official React Native documentation.
Link the native module (manually or via auto-linking).
Run the app on either an Android or iOS device using react-native run-android or react-native run-ios.
Observe the app freezing on the splash screen with no further progress.
Environment:
React Native version: (Not mentioned)
Node.js version: 16.x
npm or yarn version: npm 8.x
Operating System: macOS Big Sur
Device: iPhone 13 (iOS) / Samsung Galaxy S21 (Android)
Logs:
2025-01-25 12:34:56.789 MyApp[1234:56789] App launched
2025-01-25 12:34:57.001 MyApp[1234:56789] NativeModule: MyCustomModule initialization failed
2025-01-25 12:34:57.099 MyApp[1234:56789] App is freezing on splash screen, no further logs.
Additional Context:
I’m using a custom native module to interact with a third-party SDK.
The issue happens on both Android and iOS devices.
I’ve checked the Android logs, and the ReactContext for the module seems to be null at the time of initialization.
The app works fine when the custom module is removed.
Possible Solution (if applicable):
I’m unsure what the exact cause might be. Could this be an issue with how the native module is initialized or linked? Any ideas on how to debug further or a potential solution to this freezing problem would be greatly appreciated!
Steps to reproduce
Create a new React Native project:
npx react-native init MyApp
Navigate to the project directory:
cd MyApp
Install a custom native module (e.g., a module to integrate with a third-party SDK):
npm install react-native-custom-sdk
Link the custom native module (if manual linking is required):
npx react-native link react-native-custom-sdk
Modify the Android native code (e.g., add required permissions or SDK initialization):
Open android/app/src/main/java/com/myapp/MainActivity.java
Add necessary import and initialization code for the custom SDK.
Update App.js to use the native module:
Import and call functions from the native module inside App.js.
Build and run the app on an Android device:
npx react-native run-android
Observe the crash: The app will freeze or crash on startup with a "NativeModule: null" error or similar issue.
Clear cache and rebuild (if applicable):
npx react-native start --reset-cache
Re-run the app:
npx react-native run-android
Confirm issue persists: The app should still freeze or fail to load correctly.
React Native Version
0.77.0
Affected Platforms
Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/iaceene/react-native-custom-sdk-issue
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: