kuater
kuater

Reputation: 71

Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle'

Running my project in android studio I get that error, I just installed everything and I followed everything step by step, I'm using genymotion as an emulator, and use react-native start from the root, check port 8081, disable instant run, everything which is the following link

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

Upvotes: 7

Views: 34985

Answers (10)

sunil chilami
sunil chilami

Reputation: 109

Run a dummy project on port 8081 to ensure that the port is not being used by other processes. Run your actual project on a different port (e.g., 8088) using the --port option. When launching the app on the emulator, if you encounter the "unable to load script" error, press Ctrl+M on the emulator to bring up options. Choose "Change bundle location" and add the address 10.0.2.2:8088<-(add you actual project port) as the bundle location. This tells the emulator to load the JavaScript bundle from the specified address and port. Confirm the changes, and the app should work without encountering the port conflict error. This solution is helpful for resolving port conflicts and ensuring that your React Native app runs smoothly on the emulator. Thank you for sharing your experience!

Upvotes: 0

Mahmonir Bakhtiyari
Mahmonir Bakhtiyari

Reputation: 605

"react-native": "0.64.1",

I've resolved this problem with changing bundleInDebug: true, in project.ext.react in android > app > build.gradle.

project.ext.react = [
bundleInDebug: true,
enableHermes: ***,  
]

Upvotes: 7

gabriellend
gabriellend

Reputation: 345

For anyone that the above didn't help, I run:

adb devices

This should give you an output similar to this:

List of devices attached
98XAY181GQ  device

The numbers/letters will be different for you. Then run the following command, replacing the word "device" with the string of numbers/letters that was printed out with the previous command:

adb -s device reverse tcp:8081 tcp:8081

Then I re-run the emulator in Android studio and it works. Hope this helps someone!

Upvotes: 6

Sonia John Kavery
Sonia John Kavery

Reputation: 2129

I resolved this issue as below

  • Changed the directory to <app_name>
  • run command react-native start
  • Open Another tab in terminal
  • run command react-native run-android

Whenever we save the files, it will be automatically update in device. No need to call run app again and again.

I am using a physical device for running the app.

Upvotes: 2

Saeed
Saeed

Reputation: 3520

First of all make sure you have started the bundler using this command in root directory:

npm start 

or

react-native start

If doesn't work add assets folder manually in the following directory

android/app/src/main/{assets}

After that rename index.android.js to index.js then use the following 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

Now you can create your apk:

react-native run-android

Upvotes: 13

Ish
Ish

Reputation: 123

I also faced this problem. But couldn't find a best solution.

But after I turning off the airplane mode in the android emulator and turn on wifi, the app runs without an error.

Upvotes: 1

Slycreator
Slycreator

Reputation: 1230

I was having this issue with react-native-cli: 2.0.1 and react-native: 0.62.2

Run npm start in one terminal and in another terminal Run react-native run-android

Upvotes: 2

yet.another.coder
yet.another.coder

Reputation: 390

This usually happens in Android. To correct this, you have to change the bundle Location.

By default: it's set to localhost:8081.

For Android, you need to update to your local IP address appended with port: ip-address:8081. like xxx.xxx.x.x:8081

in Mac, you can find your Local IP address under System Preference>Network. This worked for me!

Upvotes: 2

You can check your Metro server is on or not..?

do the following command in your cmd path on your server

open two cmd window do 2nd point and 3rd point another cmd window

  1. check you localhost 8080 is running your browser chrome

like: localhost:8080

//----- then do this in your cmd path

  1. D:para\Android\testing>react-native start --port=8081

  2. D:para\Android\testing>react-native run-android --no-jetifier

That's it... check your mobile or emulator now show welcome to react...

Thank you.

Upvotes: 0

Aditya Shrivastwa
Aditya Shrivastwa

Reputation: 1

In my case , I was making a mistake in build.gradle file. you can change your targetSdkVersion from 28 to 27, minSdkVersion to 21. then you can clean your gradlew and then run react-native run-android.

Upvotes: 0

Related Questions