upgrade-support: 0.62.1 Release APK: 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.

Environment

System:
    OS: macOS 10.15.4
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 21.43 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: Not Found
    npm: 6.14.4 - ~/.nvm/versions/node/v10.16.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  Languages:
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: ^0.62.1 => 0.62.1 
  npmGlobalPackages:
    *react-native*: Not Found

Upgrading version

0.61.5->0.62.1

Description

I built my app for debug on Android, and everything works perfectly. However, when I build it for release, the build succeeds but upon launching the app it creates the following error:

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.r.a(Unknown Source:180)
 	at com.facebook.react.r.a(Unknown Source:0)
 	at com.facebook.react.r$e.run(Unknown Source:68)
	at java.lang.Thread.run(Thread.java:919)

I used this command to build my app:

cd android
./gradlew assembleRelease

Here is my build.gradle: https://gist.github.com/palkerecsenyi/1434ce9340c167b80847ea2dcee30528 app/build.gradle: https://gist.github.com/palkerecsenyi/6c09728996c4f982dc3bd11ad757c45b package.json: https://gist.github.com/palkerecsenyi/d42eb7f1af6a6d3a83db9e271e720aec index.js (not sure if that’s fully relevant): https://gist.github.com/palkerecsenyi/90274eadedb9ca9c8f4ebb0ec42f10ca

Reproducible demo

I’m not sure if this happens with all upgrades, and I’m not sure how to reproduce it. I know at least one other person has experienced this issue: https://github.com/facebook/react-native/issues/25348#issuecomment-606182604.

Thanks in advance!

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 34
  • Comments: 74 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Update

I solved this issue by doing this before each build:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

and then run

cd android
./gradlew assembleRelease

Adding the --assets-dest option to the command then gave a duplicate assets error when building, so I skipped that and it works perfectly.

Also, I tried experimenting with the version of hermes-engine, but that had no effect. This issue doesn’t seem to be anything to do with Hermes.

OK I’ve found a workaround for now. This probably isn’t a great solution since it doesn’t take into account build variants and whatnot but it works for a basic :app:assembleRelease.

I added the following to android/app/build.gradle

//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+
//Seems like there's a task ordering issue and the assets get computed before the bundle is copied
//This forces the copy task to run before merge resources
project.afterEvaluate {
        tasks.findAll { task ->
            task.name.startsWith('merge') && task.name.endsWith('Resources')
        }.each { t -> t.dependsOn "copyReleaseBundledJs" }
}

This forces gradle to run the “copy the js bundle to assets” task before the “merge assets into the apk” task. It seems that for whatever reason with gradle 4+ the task ordering can be wrong and the bundle gets moved to intermediate dir after gradle has already picked up all the assets so it never gets included in the APK.

Hopefully someone with more knowledge of gradle than I can chime in with a better solution.

I found a temp solution

I tried to change classpath('com.android.tools.build:gradle:7.1.x') with classpath('com.android.tools.build:gradle:7.0.3')

“react-native”: “0.67.4”

Seems this has resurfaced

Currently facing this issue on 0.62.2, the bundle created from gradlew bundleRelease wants to connect to the metro server somehow

Update

I solved this issue by doing this before each build:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

and then run

cd android
./gradlew assembleRelease

Adding the --assets-dest option to the command then gave a duplicate assets error when building, so I skipped that and it works perfectly.

Also, I tried experimenting with the version of hermes-engine, but that had no effect. This issue doesn’t seem to be anything to do with Hermes.

This works for me!

React native

0.69.3

gradle-wrapper.properties

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

android/build.gradle

dependencies {
        classpath('com.android.tools.build:gradle:7.0.4')
    }

This is the sequence of commands that I’ve used:

  • npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
  • cd android && ./gradlew assembleRelease
  • adb install app/build/outputs/apk/release/app-release.apk

Beginner in React Native :- For me, I am getting this error because it seems like the build script is looking assets folder inside the Android project.

So, I just created the folder: mkdir android/app/src/main/assets

and ran the command: (Found here) npx 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 --verbose

And then when I run npx react-native run-android: I can see my app.js content on android emulator. Woohoo! However, now I am trying to figure out, why are the changes not live! I can see the changes in App.js reflect immediately on iOS simulator, but not on Android emulator. But that should be a seperate thread altogether. ✌️

As a workaround, patch https://github.com/facebook/react-native/pull/30177 locally.

  1. Install patch-package
  2. curl https://github.com/facebook/react-native/commit/a6c7049f39f87885cf4d3fc486ec8a8782cf5450.diff > react-native-task-order-fix.patch
  3. patch -d node_modules/react-native < react-native-task-order-fix.patch
  4. (if using yarn) yarn patch-package react-native (if using npx) npx patch-package react-native

Pessoal, essa solução funcionou para mim:

Unable to load script from assets ‘index.android.bundle’. Make sure… Esse erro geralmente acontece porque o sistema não conseguiu criar o bundle inicial que contém todo o código Javascript da aplicação.

1- Para resolver comece criando uma pasta assets dentro da pasta android/app/src/main.

2- Logo após, execute o comando:

npx 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/

3- Agora, feche as abas do terminal e execute novamente o comando:

npx react-native run-android ou yarn run react-native run-android ou yarn android

Fonte: https://react-native.rocketseat.dev/erros/android/

Not working yet, Only works with assembleDebug and assembleRelease, with the bundleRelease fails when it’s deployed in the play store.

It’s hard to test for this to fail when the bundleRelease cannot be installed for testing, or is there a way to know it will fail before deploying?

package.json: “react”: “16.13.1”, “react-native”: “^0.63.0” “@react-native-community/async-storage”: “^1.11.0”, “@react-native-community/datetimepicker”: “^2.6.1”, “@react-native-community/google-signin”: “^4.0.3”, (recently added) “react-native-calendars”: “^1.403.0”, (recently added)@react-native-community/hooks”: “^2.6.0”, “@react-native-community/masked-view”: “^0.1.10”, “@react-native-community/netinfo”: “^5.9.5”, “@react-native-community/picker”: “^1.6.6”,

node v10.16.3 java version “1.8.0_261” com.android.tools.build:gradle:3.5.3

Crashlytics Report

Fatal Exception: 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(CatalystInstanceImpl.java) at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:2) at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:10) at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:18) at com.facebook.react.ReactInstanceManager.a(ReactInstanceManager.java:264) at com.facebook.react.ReactInstanceManager.access$000(ReactInstanceManager.java) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:68) at java.lang.Thread.run(Thread.java:919)

For me helped proper versioning according to RN changelog. to 0.69.4 in particular:

        classpath('com.android.tools.build:gradle:7.1.1')
        classpath("de.undercouch:gradle-download-task:5.0.1")
...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

@palkerecsenyi , Need to Change your Gradle Version in Main => Build.gradle in Dependencies => classpath ‘com.android.tools.build:gradle:4.0.2’ <= Working for Me Try This

same problem for com.android.tools.build:gradle:7.1.1. “react-native”: “0.67.3”,

I’m on react-native 67.2 and I’m getting this error with Gradle 7.1.1. Should I downgrade Gradle too?

Update Downgrading Gradle did fix the error for me on RN 67.2. This change in file android/build.gradle:

    dependencies {
        // classpath('com.android.tools.build:gradle:7.1.1')
        classpath('com.android.tools.build:gradle:4.1.2')

I’m getting this issue on 0.64 RN. The app doesn’t throw the red screen, just closed the app. I double checked in logs on Android Studio and show that error

I have a similar problem. i’m upgrading from 61.5 to 63.00. i changed com.android.tools.build:gradle:3.4.2 -> com.android.tools.build:gradle:3.5.3 and https://services.gradle.org/distributions/gradle-5.5-all.zip -> https://services.gradle.org/distributions/gradle-6.2-all.zip

When i launch ./gradlew bundleDevRelease i don’t find into the app.bundle the index.android.bundle. If i discard the previous changes it works. Do other people have the same mistake?

Has something changed with the new gradle?

Update

I solved this issue by doing this before each build:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

and then run

cd android
./gradlew assembleRelease

Adding the --assets-dest option to the command then gave a duplicate assets error when building, so I skipped that and it works perfectly.

Also, I tried experimenting with the version of hermes-engine, but that had no effect. This issue doesn’t seem to be anything to do with Hermes.

Work for me! But before i must Clean Project from Android Studio > Build. After ./gradlew assembleRelease run ./gradlew bundleRelease

In my case, it was an issue related to gradle version. When updating the Android API to 33, I thought I needed to update the gradle version as well, which caused the aforementioned problem. In the 0.69 announcement (the RN I use), it is stated that is is strongly recommended to stick to the provided version.

The ./gradlew assembleDebug is completely fine to me.

However the ./gradlew assembleRelease fails with error:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.

And a bunch of error like: android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_ionicons.json: Error: Duplicate resources

Then it works if I go to android/app/src/res/ and delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders.

Does anyone knows any ticket to fix this? I didn’t find.

Thank you

@palkerecsenyi that’s more like a workaround as the bundle is already generated when you run assembleRelease.

Have you tried removing this line: https://gist.github.com/palkerecsenyi/6c09728996c4f982dc3bd11ad757c45b#file-app-build-gradle-L81? just a shot in the dark here as this dictates where the bundle will be stored before being added to the .apk.

Any solid solution here that aren’t hacks?

@palkerecsenyi , Need to Change your Gradle Version in Main => Build.gradle in Dependencies => classpath ‘com.android.tools.build:gradle:4.0.2’ <= Working for Me Try This

I have solved this for RN 0.60.5 when change gradle 3.4.x to 4.1.x, this solved my problem with downgrade to 4.0.2

if you’r using proguard add an exception to android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

com.mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+
//Seems like there's a task ordering issue and the assets get computed before the bundle is copied
//This forces the copy task to run before merge resources
project.afterEvaluate {
        tasks.findAll { task ->
            task.name.startsWith('merge') && task.name.endsWith('Resources')
        }.each { t -> t.dependsOn "copyReleaseBundledJs" }
}

I have: distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip and this seems to be the only solution that works very well in my pipeline 😃 Thanks @AndrewMorsillo

This issue appears to crop up when using classpath 'com.android.tools.build:gradle:4.1.0' (4.0 or greater). Changing back to 3.6.4 works but I’d like to use 4.1.0 for other reasons. As a workaround you can manually bundle as people above have said before running ./gradlew :app:assembleRelease

Still seeing the issue and confirmed we’re using Java 8 to compile

Update

I solved this issue by doing this before each build:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

and then run

cd android
./gradlew assembleRelease

Adding the --assets-dest option to the command then gave a duplicate assets error when building, so I skipped that and it works perfectly.

Also, I tried experimenting with the version of hermes-engine, but that had no effect. This issue doesn’t seem to be anything to do with Hermes.

this worked!!

My release build crashed on launch after upgrading React Native to 0.70.6.

This article helped me…

https://articles.wesionary.team/react-native-android-release-build-crashes-fa93f07a2ba4

at first, enableVmCleanup: false for couldn’t find DSO to load: libjsexecutor.so error

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

./gradlew clean seems necessary…

steps:

$ npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
$ cd android && ./gradlew clean && ./gradlew assembleRelease  # ./gradlew bundleRelease  for aab file
$ adb install app/build/outputs/apk/release/app-release.apk

Any solution to work with the last Gradle version (7.1.1)?

if you’r using proguard add an exception to android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

com.mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

I am experiencing this issue on react-native: 0.63.2 after upgrading from a lower version. As some other users have also mentioned, I am running a classpath 'com.android.tools.build:gradle:4.1.0' which might be causing the problem. When running ./gradlew assembleRelease the APK might or might not work. This is happening kind of randomly.


I also tried running the command:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

and it does work. However, I noticed the startup time of the app is 3 TIMES LONGER than it usually is! Something unnecessary is getting bundled and making the initial parsing VERY slow.

After creating the next bundle, everything repeated