react-native: Release APK fails immediately on launch (Version 0.54)

I have a web view app that is very straightforward. The iOS version is running perfectly. The android version runs perfectly in debug mode using the package server. However, the release version of the apk crashes immediately when launched.

The errors I am getting from logcat are:

03-12 22:12:07.665 16051-16068/? E/AndroidRuntime: FATAL EXCEPTION: Thread-2
                                                   Process: com.gtcworx, PID: 16051
                                                   java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
                                                       at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:33)
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:234)
                                                       at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1113)
                                                       at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113)
                                                       at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:920)
                                                       at java.lang.Thread.run(Thread.java:764)
03-12 22:12:07.789 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.videos-fSpP8T16jLfLPEk3Hl3pmw==/base.apk
03-12 22:12:07.790 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.videos-fSpP8T16jLfLPEk3Hl3pmw==/base.apk
03-12 22:12:07.790 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.videos-fSpP8T16jLfLPEk3Hl3pmw==/base.apk
03-12 22:12:07.794 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.apps.docs.editors.slides-9EEF5YDNu3OKNBNwayfu9g==/base.apk
03-12 22:12:07.794 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.apps.docs.editors.slides-9EEF5YDNu3OKNBNwayfu9g==/base.apk
03-12 22:12:07.794 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.apps.docs.editors.slides-9EEF5YDNu3OKNBNwayfu9g==/base.apk
03-12 22:12:07.795 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.contacts-2KRJls5awi4KQQ6cjkUQQA==/base.apk
03-12 22:12:07.795 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.contacts-2KRJls5awi4KQQ6cjkUQQA==/base.apk
03-12 22:12:07.797 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.dialer-1BN26SkEVNcra4NPGyK-nA==/base.apk
03-12 22:12:07.797 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.dialer-1BN26SkEVNcra4NPGyK-nA==/base.apk
03-12 22:12:07.797 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.google.android.dialer-1BN26SkEVNcra4NPGyK-nA==/base.apk
03-12 22:12:07.798 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.799 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.799 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.799 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.800 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk
03-12 22:12:07.805 2055-2075/? E/ResourcesManager: failed to add asset path /data/app/com.gtcworx-XlyWECmWk-Pjfh6CE3jV4Q==/base.apk

since this does not use the package server, I figured the problem is that the bundle is packaged incorrectly. However, I am not sure that I can do to fix the way the package is bundled.

I did some searches and noticed that this problem is caused the View.propTypes references. I followed the steps to see if there were any such references in my modules and there are not. There are only comments referring to the issue and explaining the patches put into place.

I also found an article that suggested I check the name of the app in the index.js file and compare that with the name in the MainActivity. I checked those and they are identical. I also checked my package.json for the same name.

I have also done several cleans of the project using Gradle.

Thanks for any help that can be provided.

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 8.8.1
  Yarn: 1.3.2
  npm: 5.4.2
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
  react: ^16.2.0 => 16.2.0
  react-native: ^0.54.2 => 0.54.2

Expected Behavior

I expected the app to launch and show the website in the webView.

I am unable to reproduce the error in snack, but here is the link that shows how it should work: https://snack.expo.io/r1JzDYSFG

Actual Behavior

dialog box shows up saying “app has stopped” and ask to open again.

Steps to Reproduce

  1. Create a web view app
  2. Build it using the versions of the libs I have above
  3. Generate a signed release apk
  4. Install release apk onto device
  5. Run the app

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 15
  • Comments: 68 (2 by maintainers)

Commits related to this issue

Most upvoted comments

The issue for me was fixed by:

• Within your projects build.gradle change the buildScripts dependencies classpath to ‘com.android.tools.build:gradle:3.1.4’ // I wasn’t able to get v3.2.0 to work, so I had to downgrade to 3.1.4. This might work with lower versions too, but I haven’t tested it. • Placing android.enableAapt2=false within the gradle.properties. • Within the terminal on the Project folder enter cd android && ./gradlew clean assembleRelease • Within the terminal on the Project folder enter react-native run-android --variant=release to verify that the app-release.apk works properly.

I’ve tried with and without ‘org.gradle.configurationOnDemand=false’ with no difference to being able to build. I’m also running react-native: 0.56.1

Hope this helps someone.

Apparently, Gradle 3.2.0 changed the location to which it generates asset bundles. RN expects its JS asset bundle to be in a specific path, which is the path used by Gradle 3.1.4. Because G3.2.0 puts them in a different spot, RN cannot find the JS asset bundle, and thus the files with the Javascript to run. Ergo, the crash in release mode.

In debug mode, the JS files are provided by the Metro daemon, and there is no JS asset bundle to be loaded. That’s why this error only manifests itself in release mode.

This is why lots of people suggest fixes that involve creating the asset bundle manually (via CLI), copying it manually to a specific folder, and then running the apk generator. But, let’s face it, it’s way easier to just downgrade Gradle to a version that works the way RN expects.

Now, why the RN devs didn’t update the native source code to get the bundle from its new location, that is a mystery that I haven’t figured out.

The fix is upgrading RN to 0.57.4 or downgrading gradle to 3.1.4.

For those who want a really neat workaround without having to upgrade/downgrade: app/build.gradle:

project.ext.react = [
    entryFile: "index.js",
    jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out"
]

I can confirm versions that @Bvida100 stated.

For beginners or confused how to downgrade you can do that in following config files:

android/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

and

android/build.gradle:

dependencies {
...
    classpath 'com.android.tools.build:gradle:3.3.0'

Best to do that from Android Studio by opening android solution. It should prompt to sync gradle, do that and sync should be successful.

I have the same problem with latest gradle (4.10.1) and latest react-native (0.57). I’m building without Android Studio, just from the command line with gradlew clean assembleRelease.

The apk is created, but in assets the file index.android.bundle is missing. It is created during build to build\intermediates\assets\release and build\generated\assets\react\release but not included into the apk.

I have tried several things like setting org.gradle.configureondemand=false even if it was missing, adding bundleInRelease: true, manually setting main.assets.srcDirs to the directories above, turning of org.gradle.parallel, changing the order of entries in build.gradle, … Nothing worked.

An other thing I’m wondering: After the apk is already created still a lot of tasks buliding react-nativ projects are running. I would expect building the apk must be the last step.

Have the same issue. I’m using Build -> Generate signing APK in android studio. But I’m using “react-native”: “0.54.0”

Experiencing the same issue with RN 0.55.3

Well. It’s working with react-native run-android --variant=release and with ./gradlew assembleRelease and configuring signing. Also I’ve updated gradle and should set android.enableAapt2=false. Probably issue connected with gradle update.

Root cause well explained here --> https://github.com/facebook/react-native/issues/18357#issuecomment-437186504, thanks @jsaraiva

"react-native": "0.58.5" with com.android.tools.build:gradle:3.3.0 is also a working combination if you want to use a newer version of gradle.

Thanks everyone for your help, it was painful to face this issue.

I am using: com.android.tools.build:gradle:3.2.1 react-native": "0.53.0 gradle 4.6

first make sure you have no untracked files/directories that you would like to commit. (VERY IMPORTANT) run this command:

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

This will create the bundle and bundle.meta file in android/app/src/main/assets/ and some other files and directories in android/app/src/main/res/

Add the files in android/app/src/main/assets/

git add android/app/src/main/assets/*

Next remove the files and directories that are not needed

To see what will get removed(This will not actually remove them so you are safe)

git clean -n

If you are ok with this output remove them all.(Make sure you dont have files/directories that you want to keep in this ourput. You will lose them. You have been warned)

git clean -d -f

Build the release app with

react-native run-android --variant=release

Same Problem react-native: 0.56.0 and 0.57.1 on Mac OS

Maybe, It can help It’s working for me if in yourgraddle.properties you have: org.gradle.configureondemand=true Task for assemble JS and Assets doesn’t run

If it’s removed, all work as expected

I am having the same issue. Works fine in debug but once I release the APK it crashes on load. Here are my packages. “dependencies”: {

	"axios": "^0.18.0",
	"react": "16.4.1",
	"react-native": "0.55.4",
	"react-native-elements": "^0.19.1",
	"react-native-material-dropdown": "^0.11.1",
	"react-native-push-notification": "^3.0.2",
	"react-native-swipeout": "^2.3.3",
	"react-native-vector-icons": "^4.6.0",
	"react-navigation": "^2.6.2",
	"react-redux": "^5.0.7",
	"redux": "^4.0.0",
	"redux-axios-middleware": "^4.0.0",
	"redux-thunk": "^2.3.0",
	"round-to": "^3.0.0"
},
"devDependencies": {
	"babel-jest": "23.2.0",
	"babel-preset-react-native": "^4.0.0",
	"jest": "23.3.0",
	"react-test-renderer": "16.4.1"
},
"jest": {
	"preset": "react-native"
}

I see info on downgrading react-native but nothing has worked for me. My app is in production and need help asap. Any ideas?

Im using Android Studio to generate the release version of the app. Its taking me through the same steps that I have using for Java-based Android apps without problems.

@taeminpak I believe there were a lot of changes since 0.57.4 and even some breaking ones with the releases of 0.58 and 0.59.

If possible you could try RN v0.59.9, because it has support for more recent build tools. If not I would suggest retrieving logs from device running release version of your app and the issue might not be connected to this one.

Regarding AndroidX recent release of Google Play Services has impacted some libraries that were using its latest version (i.e. react-native-device-info), but that’s unlikely because it would probably crash on build first.

I also had some issues in the past regarding drawables and not having asset of required density so app would crash.

Would suggest you to create a new fresh project and add your current dependencies to see if problem is actually in current build tools and RN version.

You could also take a look at RN Changelog to see if something has been fixed with newer versions. It’s always like playing cat and mouse unfortunately.

Good luck! 😃

I have tried upgrading to versions suggested by @remarcus and @thib92 and am still finding the app crash on launch (for release versions only). My RN version is “0.57.4”. I am following these directions to generate the release APK: https://medium.com/@impaachu/react-native-android-release-build-crash-on-device-14f2c9eacf18 I have also tried generating the release APK through Android Studio, but I get the same result. Anyone have any suggestions? Also does anyone know if using AndroidX has any effect on the release build process?

I had same problem with android 3.4.0 and gradle 5.4.1, I downgrade to android 3.3 and gradle 4.10.1 and the issue is gone. I use React Native 0.59.5.

The fix is upgrading RN to 0.57.4 or downgrading gradle to 3.1.4.

For those who want a really neat workaround without having to upgrade/downgrade: app/build.gradle:

project.ext.react = [
    entryFile: "index.js",
    jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out"
]

hello, it is not working for me , help plz

@jsaraiva got it, thanks! I’ll try that

@paalex I managed to get it to work without the enableAapt2 = false part. What was mandatory was downgrading gradle to 3.1.4. RN 0.57.2

@bhardman1986 You are my hero!

#21409 fixed it, thank you @edilaic !

I have the same problem @react-native-bot , your solution is not feasible to change the native version of react, which requires making many changes in the project: As you could verify that the generated apk is correct, there is some way. Please help us thanks. Versions react-native-cli: 2.0.1 react-native: 0.55.4

Add this lines

project.ext.react = [
        entryFile: "index.js",
        bundleAssetName: "index.android.bundle",
        bundleInAlpha: true,
        bundleInBeta: true
]

before apply from: "../../node_modules/react-native/react.gradle" in build.gradle

I’m using version 0.55.4 and it’s not working, currently using a hacky workaround to use Android Studio:

  • cd android && ./gradlew assembleRelease (create the bundle)
  • Android Studio -> Build -> Generate Signed APK (generate a signed apk)

Another option is generating signed apks using command line as suggested by @alexmbp. This procedure is described here.