Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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. #38

Open
palkerecsenyi opened this issue Apr 4, 2020 · 74 comments

Comments

@palkerecsenyi
Copy link

palkerecsenyi commented Apr 4, 2020

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: facebook/react-native#25348 (comment).

Thanks in advance!

@palkerecsenyi
Copy link
Author

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.

@lucasbento lucasbento added 0.62.1 and removed 0.61.5 labels Apr 6, 2020
@lucasbento
Copy link
Member

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

@palkerecsenyi
Copy link
Author

Thanks for the reply @lucasbento! I tried commenting that line out, and once again the build finished perfectly. However, when launching the app I got a different fatal error:

com.facebook.jni.CppException: Could not get BatchedBridge, make sure your bundle is packaged correctly
 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
 	at android.os.Handler.handleCallback(Handler.java:883)
 	at android.os.Handler.dispatchMessage(Handler.java:100)
 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
	at android.os.Looper.loop(Looper.java:237)
 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
 	at java.lang.Thread.run(Thread.java:919)

I tried running with both npx react-native run-android --variant=release and ./gradlew assembleRelease but both of them give the same error.

@palkerecsenyi
Copy link
Author

Update

Commenting out these lines fixed it, and my app runs successfully (with Hermes enabled):

if (useIntlJsc) {
    implementation 'org.webkit:android-jsc-intl:+'
} else {
    implementation 'org.webkit:android-jsc:+'
}

@Ayyanchira
Copy link

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. ✌️

@palkerecsenyi
Copy link
Author

@Ayyanchira I'm not completely sure, but I think it might have something to do with the fact that you've set --dev false in the bundle command.

Try using this instead:

npx react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res --verbose

Again, I'm not too sure about this. In debug mode, I usually do this:

cd android
./gradlew assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk

cd ..
npx react-native start

and then launch the app on the phone/emulator. This seems to work fine and was unaffected by the update to 0.62.x

@wilsolutions
Copy link

wilsolutions commented Apr 7, 2020

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

@Taynan-Vieira
Copy link

Taynan-Vieira commented Apr 22, 2020

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/

@Relax594
Copy link

Facing this issue even in debug build. Any solid solution yet?

@duncte123
Copy link

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

@singhvivek2503
Copy link

@duncte123 Did you find a solution to this?

@duncte123
Copy link

@duncte123 Did you find a solution to this?

Yes I did, I compiled on java 11 for some reason. Switching to java 8 solved the issue.

@lfalkner
Copy link

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

@jstheoriginal
Copy link

I had this issue last week and the root cause was that it was using node 13 (the system version on my Mac - Big Sur) to bundle rather than node 10. Once I forced it to use node 10, it finally stopped crashing for release bundles. For some reason nvm stopped working 🤷‍♂️.

@Imperyall
Copy link

@lfalkner Still seeing the issue and confirmed we're using Java 8 to compile

You did not find a solution?

@Imperyall
Copy link

Imperyall commented Jul 8, 2020

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

Same problem, java 8 version

@jstheoriginal
Copy link

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

Same problem, java 8 version

Which node version are you using when you put node -v in the command line in your project directory?

@Imperyall
Copy link

@ duncte123 В настоящее время сталкивается с этой проблемой на 0.62.2, пакет, созданный из gradlew bundleReleaseхочет как-то подключиться к серверу метро

Та же проблема, версия Java 8

Какую версию узла вы используете, когда помещаете node -vв командную строку в каталоге вашего проекта?

v13.11.0

@jstheoriginal
Copy link

That’s the same issue I had. It doesn’t work.

If you change it to use 10.16.3, does it work? That was my issue and it resolved once I used that older node version.

@Imperyall
Copy link

Это та же проблема, что и у меня. Не работает

Если вы измените его на использование 10.16.3, это работает? Это была моя проблема, и она разрешилась, когда я использовал ту старую версию узла.

Switch to v10.21.0, nothing has changed

@jstheoriginal
Copy link

I did have one other thing that might be required as well. I set the metro preset to exactly 0.58.

@lorenzoangelini
Copy link

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?

@Imperyall
Copy link

I solved the problem when changing the build tools version from 4.0.1 to 3.5.3

@Imperyall
Copy link

After creating the next bundle, everything repeated

@fabianmedina09
Copy link

fabianmedina09 commented Sep 8, 2020

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)

@evelant
Copy link

evelant commented Oct 13, 2020

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

@code-by
Copy link

code-by commented Nov 23, 2021

@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

@Stas-Buzunko
Copy link

I've tried many suggestions but only downgrading from gradle:4.2.1 to gradle:4.0.2 fixed the issue.
I'm also on RN 0.60.5

@felipezf
Copy link

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

@brownieboy
Copy link

brownieboy commented Feb 26, 2022

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')

@Rubon72
Copy link

Rubon72 commented Mar 4, 2022

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

@abouquet
Copy link

Same issue here guys ...

@giacomosardo
Copy link

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"

@AndreaGProg
Copy link

AndreaGProg commented May 18, 2022

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

@abouquet
Copy link

Got for a second time the same issue

"react-native": "0.69.3"
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip

@foxbit19
Copy link

foxbit19 commented Aug 9, 2022

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

@airowe
Copy link

airowe commented Aug 23, 2022

Any solid solution here that aren't hacks?

@zakharchenkoAndrii
Copy link

zakharchenkoAndrii commented Aug 30, 2022

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

@koploop
Copy link

koploop commented Sep 21, 2022

For me this problem appear with React Native 0.68 and JDK 11

i hava checked the jsBundleDirRelease (in build.gradle) and the bundle exist,so why ?

im a little confused and depressed when my last project solved many build problems finaly published to store but when create a new project use npx react-native init xx,new problem appear...

@abouquet
Copy link

Got it working by launching gradlew assemble twice.

Yes... a bit hacky ...

@sachiotomita
Copy link

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

@anas-araid
Copy link

same issue after upgrading react-native from 0.64.3 to 0.68.2.

classpath("com.android.tools.build:gradle:7.0.4")
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

running this command before each build gets the job done, but it seem like a quick workaround.

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

is there a more solid solution for this issue?

@simonmasinde
Copy link

Seems this has resurfaced

@yogeshBright
Copy link

face this issue while upgrading react native version from 0.65.3 to 0.70.9. do any have solid steps to resolve this issue ?

@yogeshBright
Copy link

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

Thanks for putting this information here. you saved my day. 😍😍😍

@tahola
Copy link

tahola commented May 31, 2023

Same issue here, build work fine but when downloading from playstore I get this error, any idea ?

@metropontikas
Copy link

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.

@KelvinPortuphy
Copy link

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!!

@tpurg
Copy link

tpurg commented Sep 7, 2023

I'm not sure which of these things really fixed it for me, but after 3 days of trying to figure this out here's what I changed to make it work without hacks and allowing to make hot reloading still work in dev:

  • Removed node_modules, package-lock.json
  • I switched to node version 18.7.1 with nvm
  • I added android:usesCleartextTraffic="true" in AndroidManifest.xml
  • ran npm udpate
  • But what I think sealed the deal, was going to settings of my phone and deleting the apps cache and data
    Hopefully it works, this error is just so out of nowhere.

@1guzzy
Copy link

1guzzy commented Jan 11, 2024

I was having this issue with RN 0.70.13 and fixed my issue by going to File > Project Structure in Android Studio and downgrading AGP to 7.2.1. This version is specified in the react native release announcement here

cheers!

@SoniCoder
Copy link

In my case on Windows I had 8081 already occupied due to a portproxy config I did .. removing that fixed it

@CallMeProteus
Copy link

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

this is what worked for me as well, for :"react-native": "0.73.4", but had to manually create the folder assets first with:
mkdir -p android/app/src/main/assets
then
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output [android/app/src/main/assets/index.android.bundle](http://android/app/src/main/assets/index.android.bundle) --assets-dest android/app/src/main/res

then cd android
and finally ./gradlew assembleDebug or ./gradlew assembleRelease.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests