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

Viewed 7806

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",

4 Answers

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

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.

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

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

Related