Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

App freezes on startup after adding custom native module #48944

Open
iaceene opened this issue Jan 25, 2025 · 2 comments
Open

App freezes on startup after adding custom native module #48944

iaceene opened this issue Jan 25, 2025 · 2 comments
Labels
Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue.

Comments

@iaceene
Copy link

iaceene commented Jan 25, 2025

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

React Native Environment Info:
    System:
      OS: macOS 12.5.1
      CPU: (8) arm64 Apple M1
      Memory: 16 GB
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.14.2 - /usr/local/bin/node
      Yarn: 1.22.18 - /usr/local/bin/yarn
      npm: 8.3.1 - /usr/local/bin/npm
      Watchman: 2021.08.02.00 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 15.2, macOS 12.1, tvOS 15.2
        Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
      Android SDK:
        API Levels: 30, 29, 28
        Build Tools: 30.0.3, 29.0.3
        Platform Tools: 31.0.3
        Android NDK: 23.1.7779620
    IDEs:
      Xcode: 13.2.1 - /usr/bin/xcodebuild
      Android Studio: 2021.1.1.25 - /Applications/Android Studio.app/Contents
    Languages:
      Java: 11.0.9.1 - /usr/bin/javac
      Kotlin: 1.5.30 - /usr/local/bin/kotlinc
      Python: 3.9.7 - /usr/bin/python3
    npmPackages:
      react: 18.0.0 - node_modules/react
      react-native: 0.67.2 - node_modules/react-native
    Expo:
      SDK: N/A
    Installed Android Emulators:
      Pixel_3_API_30: Android 10 (API 30) - emulator
      Pixel_4_API_31: Android 11 (API 31) - emulator

Stacktrace or Logs

2025-01-25 12:34:56.789 MyApp[1234:56789] App launched
2025-01-25 12:34:56.890 MyApp[1234:56789] React Native: Starting up...
2025-01-25 12:34:56.999 MyApp[1234:56789] NativeModule: CustomSDK initialization failed
2025-01-25 12:34:57.123 MyApp[1234:56789] Error: Attempt to invoke virtual method 'com.reactlibrary.CustomSDK.getReactApplicationContext()' on a null object reference
    at com.myapp.MainActivity.onCreate(MainActivity.java:45)
    at android.app.Activity.performCreate(Activity.java:8024)
    at android.app.Activity.performCreate(Activity.java:8014)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3543)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3717)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2126)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8637)
    at java.lang.reflect.Method.invoke(Method.java:0)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

Reproducer

https://github.com/iaceene/react-native-custom-sdk-issue

Screenshots and Videos

No response

@sarthak-d11
Copy link
Collaborator

Hey @iaceene , I’m unable to access the reproducer you shared (https://github.com/iaceene/react-native-custom-sdk-issue) as it’s showing a 404 error. Would it be possible for you to share a valid reproducer?

@sarthak-d11 sarthak-d11 added Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. and removed Needs: Triage 🔍 labels Jan 27, 2025
@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue.
Projects
None yet
Development

No branches or pull requests

3 participants