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
@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.
Log:
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
@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