-1

My react native project is failing to launch in Android Studio. I am running Metro (ran command line 'npx react-native start' in the project root directory) but the below message appears.

enter image description here

I am able to launch the project with no issues using terminal with the command line 'npx react-native run-android'.

Can someone please assist? I would like to run my project using the emulator in Android Studio and not via terminal.

Error when debugging:

E/unknown:ReactNative: Exception in native call java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method) at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:234) at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29) at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:263) at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1293) at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1023) at java.lang.Thread.run(Thread.java:920) D/CompatibilityChangeReporter: Compat change id reported: 171***; UID 10***; state: ENABLED I/FA: Tag Manager is not found and thus will not be used W/unknown:ReconnectingWebSocket: Couldn't connect to "ws://localhost:8081/message...", will silently retry

AJDee
  • 147
  • 1
  • 14

1 Answers1

0

Steps to run react-native project in Android Studio:

  1. npm start --reset-cache (it will pop-out a terminal for js-bundling).
  2. open project root android folder in android studio.
  3. wait until build project && if you get any error then resolve it.
  4. after successful build project in android studio "Run" your App. (In case you want to use break-points "Debug-Run" your App.).
  5. Done
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Thanks but I'm still getting the same issue. Above is what I see when debugging. FYI, for step 2 I open my project android folder using command line 'open -a /Applications/Android\ Studio.app' because the build fails with the error 'Caused by: java.io.IOException: Cannot run program "node" (in directory "/..../...")...' when launching Android Studio directly – AJDee Sep 20 '22 at 06:50
  • can you plz share your exact error in text format? – Virendrasinh R Sep 21 '22 at 07:40
  • please see error in text above – AJDee Sep 22 '22 at 07:05
  • Can someone please help? I would really appreciate it. I'm not too sure where I'm going wrong here. – AJDee Sep 23 '22 at 14:02
  • can i get an access of your code if you don't mind? – Virendrasinh R Sep 26 '22 at 06:12
  • Using the following command to delete any bundles manage to resolve issue: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res. However, I noticed that whenever I modify my code the change doesn't appear instantly in the emulator. I am having to restart android, delete any bundles with the command mentioned and relaunch the emulator to see the change – AJDee Sep 26 '22 at 19:37