Skip to main content

Command Palette

Search for a command to run...

Fixing React-Native android release build

Android release build crashes on launch but works fine in development mode.

Updated
3 min read
Fixing React-Native android release build
B

I'm Binaya, a full-stack software engineer based in Canada, passionate for transforming complex ideas into efficient software solutions. Interested in Artificial Intelligence, Machine Learning, DevOps, System Design, and Distributed Systems.

After devoting several months to meticulous research and development, your app is finally ready for release. Filled with boundless excitement and a sense of achievement, you look forward to introducing your million-dollar app to the world. You then follow every step mentioned in React-Native’s official guide to generate a production-ready .apk file for testing your app before publishing it to the Google Play Store.

Subsequently, you execute the following command in a terminal to compile and generate a production build .apk file; the generated file will be located under android/app/build/outputs/apk/release/app-release.apk.

cd android
./gradlew assembleRelease

After generating the .apk file, you install it on your Android device, and as soon as you open the app, it crashes.

You don’t know what went wrong; you start rechecking to see if you missed any steps mentioned in the React-Native documentation; you start searching for solutions on StackOverflow and Github and try out all the random solutions you discovered. You feel frustrated, stressed out, and filled with self-doubt. Imposter syndrome kicks in, and you regret choosing React-Native over other mobile development frameworks.


TL;DR: I had a similar feeling after going through a lot of answers and comments on StackOverflow and GitHub issues. Here are the steps I followed to find and fix the issues with the release build.

Using Logcat CLI to determine the issue

Connect your device to your machine (ensure USB debugging is ON) and run the following command on your terminal.

adb logcat '*:E'

Find out more about Logcat CLI syntax here.

After running the logcat tool to log system logs, I had two issues that were causing the application to crash.

1. couldn’t find DSO to load: libjsexecutor.so

java.lang.UnsatisfiedLinkError: couldn’t find DSO to load: libjsexecutor.so

I solved libjsexecutor.so error by adding enableVmCleanup: false in build.gradle file inside project.ext.react array as mentioned in the GitHub comment here.

project.ext.react = [
    enableHermes: true,     // clean and rebuild if changing
    enableVmCleanup: false, //this
]

2. java.lang.RuntimeException: Unable to load script.

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.

To solve this issue follow the steps below

  • Remove index.android.bundle from android/app/src/main/assets if the file already exists or just run the following command (ensure you’re on your project’s root directory).
rm android/app/src/main/assets/index.android.bundle
  • For generating your android bundle run the command given below, this will generate index.android.bundle file inside android/app/src/main/assets
npx react-native bundle \
--platform android \
--dev false \
--entry-file index.js \
--bundle-output android/app/src/main/assets/index.android.bundle
  • Now run the following command to generate a release build
cd android
./gradlew clean
./gradlew assembleRelease

Hopefully, this will fix your app's crashing problem, and your app should be ready for deployment.

Feel free to provide any feedback and improvements, happy coding…