Esteban Contreras
Esteban Contreras

Reputation: 503

Unable to load script. Make sure you're either running a metro server or that your bundle 'index.android.bundle' is packaged correctly for release

enter image description here

Hello have you experienced this error after generate an apk with command ./gradlew assembleDebug ??

I just see this error after download the apk on my android phone...

"react-native": "~0.61.5",

Upvotes: 7

Views: 13365

Answers (7)

Inderpreet Singh
Inderpreet Singh

Reputation: 1

The issue occurs because the Android app is using a manually bundled index.android.bundle file, which disconnects it from Metro Bundler and blocks live updates. To fix this, ensure the assets folder exists using mkdir -p android/app/src/main/assets, then bundle the app with:

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

After bundling, then run the app using npx react-native run-android to reconnect it to Metro. If a manual bundle exists, delete index.android.bundle from android/app/src/main/assets to avoid conflicts. This ensures your Android app reflects changes instantly during development.

Upvotes: -1

office fineoutput
office fineoutput

Reputation: 11

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

Upvotes: 0

Tiago Barroso
Tiago Barroso

Reputation: 387

I was facing this problem because I was not starting the Reactive Native service itself.

You can run directly:

react-native start

Metro will give you the option to run on Android.

Upvotes: 0

Sourabh Gera
Sourabh Gera

Reputation: 1006

npx react-native run-android --port=1234

go to android folder ./gradlew clean

and go back to your project

and npx run react-native run-android

Upvotes: 1

Swarnim Prabhat
Swarnim Prabhat

Reputation: 51

Recently I tried to create and run in windows 10 by referring the link https://reactnative.dev/docs/environment-setup. I too face same issue and I figure out that this is because by default mobile device try to search build in port 8081. So I gave this command to change the port and run npx react-native run-android --port=1234 and it worked.

Upvotes: 2

Benjamin Heinke
Benjamin Heinke

Reputation: 2992

I had to add the Android SDK path to my .bash_profile or .zshrc:

export ANDROID_SDK=/Users/<username>/Library/Android/sdk export PATH=/Users/<username>/Library/Android/sdk/platform-tools:$PATH

Upvotes: 0

Pushan Gupta
Pushan Gupta

Reputation: 3825

The apk that you built is still debug version.

./gradlew assembleDebug

Thats why it still need the metro server to debug and run normally.

If you want to test out a release version of the apk you need to build and run the apk in release mode:

Either, build a signed apk https://reactnative.dev/docs/signed-apk-android or

Let react native run a release variant on your device(you may still need metro server)

react-native run-android --variant=release

If the above command doesn't work try:

react-native run-android --configuration=release

Upvotes: 7

Related Questions