'Why does this error appear when building release build and causes crash but not with emulator or usb debug?

I am having an issue where the application that is build using ./gradlew bundleRelease (aab) or ./gradlew assembleRelease (apk). At the moment when user clicks the application it crashes straightaway and this issue doesn't happen on emulator when building the application using npx react-native run-android or using the real device through usb debugging.

In the google play developer console I got the following error that shows up

FATAL EXCEPTION: create_react_context
Process: com.vahingonsattuessa, PID: 18803
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'npx 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:248)
    at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29)
    at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:277)
    at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1408)
    at com.facebook.react.ReactInstanceManager.access$1200(ReactInstanceManager.java:138)
    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1104)
    at java.lang.Thread.run(Thread.java:764)

And

java.lang.RuntimeException: 
  at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets (Native Method)
  at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets (CatalystInstanceImpl.java:248)
  at com.facebook.react.bridge.JSBundleLoader$1.loadScript (JSBundleLoader.java:29)
  at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle (CatalystInstanceImpl.java:277)
  at com.facebook.react.ReactInstanceManager.createReactContext (ReactInstanceManager.java:1408)
  at com.facebook.react.ReactInstanceManager.access$1200 (ReactInstanceManager.java:138)
  at com.facebook.react.ReactInstanceManager$5.run (ReactInstanceManager.java:1104)
  at java.lang.Thread.run (Thread.java:923)

Any ideas why this happens and how would I be able to fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source