react-native run-android
command terminates by leaving a message in android simulator. The message is as follows:
Unable to load script.Make
You can try the following:
Add this line on your AndroidManifest.xml
<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>
After try to solve this problem in my workspace I found a solution.
This error is because there are a problem with Metro using some combinations of NPM and Node version.
You have 2 alternatives:
Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js
and change this code:
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
and change to this:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Please note that if you run an
npm install
or ayarn install
you need to change the code again.
These steps really help me:
Step 1: Create a directory in android/app/src/main/assets
Linux command: mkdir android/app/src/main/assets
Step 2: Rename index.android.js
(in root directory) to index.js
(Maybe there is an index.js
file in which case you do not need to rename it) then run 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
Step 3:
Build your APK: react-native run-android
Please use index.js in latest version.
Enjoy :)
if you have everything correctly configured then try this:
adb reverse tcp:8081 tcp:8081
Why? "When the RN packager is running, there is an active web server accessible in your browser at 127.0.0.1:8081. It's from this server that the JS bundle for your application is served and refreshed as you make changes. Without the reverse proxy, your phone wouldn't be able to connect to that address."
all credits to Swingline0
I experienced this just because my Wifi was mistakenly turned off on my emulator.i turned it back on and it started working fine. Hope it's helpful to someone
First do steps 4 and 5 then you can run your project. If you do not get the result (with steps 4 and 5) do the following steps
1- Try to downgrade your Node version (current version is 12.13.1
)
choco uninstall nodejs
choco install nodejs --version 12.8
2- Add the path of npm module (C:\Users\your user name\AppData\Roaming\npm
) to system variables instead of user variables
3- Install react native globally by using command
npm install -g react-native-cli
4- Go to the root of your project directory and run the following command :
react-native start
5- Open another terminal in the root of your project and run the following command :
react-native run-android
EDIT :
You are using Genymotion ? If yes, do the following step :
After above step if you get the following error ?
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
Open your genymotion and go to :
genymotion menu -> Settings -> ADB -> Then select use custom android sdk tools (click on browse to find sdk location)
Finally , run you project again ..