Unable to load script. Make sure you're either

2020-04-14 09:06发布

问题:

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

回答1:

First of all create a directory in android/app/src/main/assets

(Add assets folder manually)

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

And finally build your APK: react-native run-android



回答2:

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.



回答3:

I resolved this issue as below

  • Changed the directory to
  • Called react-native start
  • Open Another tab in terminal
  • Called 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 real device for running the app.



回答4:

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.