react-native: App Crash in Release Build --- FATAL EXCEPTION: create_react_context

Description

I can build in debug mode, it works fine, but when I get release build, it gets build, but the application breaks, you can see the error output here.

React Native version:

“react-native”: “0.62.2”,

##Error

Name
FATAL EXCEPTION: create_react_context
Reason
java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
Stacktrace
FATAL EXCEPTION: create_react_context
Process: com.seeandsign.papilon, PID: 27990
java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (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(Unknown Source:2)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(Unknown Source:10)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(Unknown Source:18)
at com.facebook.react.q.q(Unknown Source:180)
at com.facebook.react.q.b(Unknown Source:0)
at com.facebook.react.q$e.run(Unknown Source:68)
at java.lang.Thread.run(Thread.java:764)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 18

Most upvoted comments

@grkemtneri This is not a good solution, you are generating code (index.android.bundle) inside source folder (android/app/src/) during build phase…

react.gradle tasks will generate it in build folder (build/generated/assets/react/…). But like @rahulson says, with latest version of com.android.tools.build:gradle, index.android.bundle is not copied inside APK. I downgraded to 'com.android.tools.build:gradle:4.0.2' & it’s works too.

@grkemtneri I faced same issue so I changed gradle plugin version in project gradle from 4.1.1 to 4.0.1 Then clean, rebuild and generate apk and now it is working fine

it;s a known issues that is fixed on RN version 0.63.4 https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#v0634

Here is the commit with changes https://github.com/facebook/react-native/commit/53f55001afbf07494de0df064a92dfdd42f37c98

If. you don’t want to upgrade RN version just copy react.gradle file from node_modules in your project and apply that instead of the one from node_modules

Still exists in RN 0.64.2.

buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
classpath("com.android.tools.build:gradle:4.1.0")
enableHermes: true

Log:

2021-06-24 11:07:58.748 1007-5213/? E/ActivityTaskManager: Checking for the Active launch isDataCleared :false, isAutoRunBlocked : true
2021-06-24 11:07:58.814 15692-15692/? E/.*****.app: Not starting debugger since process cannot load the jdwp agent.
2021-06-24 11:07:58.850 1007-5176/? E/PkgPredictorService-Collector: record changed bt=0  wifi=1 screen=0
2021-06-24 11:07:58.888 15692-15692/? E/SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: dlopen failed: library "libjsc.so" not found: needed by /data/app/~~8NygCsdZ2mcU-SK5ss4onA==/com.*****.app-Kpu6H-gmP1-P0kwqnSKSOA==/lib/arm64/libjscexecutor.so in namespace classloader-namespace result: 0
2021-06-24 11:07:58.943 15692-16083/? E/SoLoader: couldn't find DSO to load: libhermes-executor-debug.so caused by: dlopen failed: cannot locate symbol "_ZN8facebook6hermes13HermesRuntime11getDebuggerEv" referenced by "/data/app/~~8NygCsdZ2mcU-SK5ss4onA==/com.*****.app-Kpu6H-gmP1-P0kwqnSKSOA==/lib/arm64/libhermes-executor-common-debug.so"... result: 0
2021-06-24 11:07:58.998 601-647/? E/HYPER-HAL: [Request.cpp]acquire(): Request:: id : 526870, No Resource to set
2021-06-24 11:07:59.012 15692-16083/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.*****.app, PID: 15692
    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:923)

react.gradle tasks will generate it in build folder (build/generated/assets/react/…). But like @rahulson says, with latest version of com.android.tools.build:gradle, index.android.bundle is not copied inside APK. I downgraded to 'com.android.tools.build:gradle:4.0.2' & it’s works too.

I have the same issue today but downgrading com.android.tools.build:gradle:4.0.2 gives me an error: No version of NDK matched the requested version

I am using com.android.tools.build:gradle:4.1.0 App build is successful but the app crashes upon start, app opens then close right away.

what to do?

thank you for your reply. I found solution npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

@grkemtneri I faced same issue so I changed gradle plugin version in project gradle from 4.1.1 to 4.0.1 Then clean, rebuild and generate apk and now it is working fine

@rahulson Thank you for your solution 😃. This worked for me. I did the same and it worked.

This is a simple cache issue. Invalidate caches from android studio and rebuild project properly. This worked for me everytime I faced this issue