320

react-native run-android command terminates by leaving a message in android simulator. The message is as follows:

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.

Screenshot

What am I doing wrong?

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Belle Solutions
  • 3,231
  • 2
  • 7
  • 4
  • can you tried this link https://stackoverflow.com/questions/32572399/android-failed-to-load-js-bundle ? – errorau Mar 31 '19 at 14:54
  • 18
    I have the same problem because my device is not connected to the internet. – Holi Boom May 22 '19 at 01:44
  • This error comming: throw er; // Unhandled 'error' event – Saeed May 31 '19 at 15:36
  • 1
    i found it and put it down https://stackoverflow.com/a/58570426/6852210 – Alireza Dec 03 '19 at 06:41
  • Mybe this will help you. https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff – blue dream Apr 07 '20 at 14:17
  • I had this error with AVD. I just opened the Android Studio> AVD Manager > Wipe Data. It worked for me. – JmLavoier Jul 24 '20 at 13:04
  • 1
    Please make sure your mobile data or Wi-Fi is turned on(this was the problem for me). If so then try the alternatives prescribed here – ThinkAndCode Dec 30 '20 at 08:10
  • I had try all solution below commented and answered by different people. Some Times it work but some times no one solution for me..... best solution for this error uninstall apk from physical device and and run app once again ...its work for me 100% !!! – Avishkar Patil Jul 09 '21 at 05:36
  • it helps me: https://medium.com/geekculture/react-native-generate-apk-debug-and-release-apk-4e9981a2ea51 – Mikhail Ionkin Apr 04 '23 at 13:26

64 Answers64

200

You haven't started the bundler yet. Run npm start or react-native start in the root directory of your project before react-native run-android.

Shaishav
  • 5,282
  • 2
  • 22
  • 41
Nerdragen
  • 2,976
  • 2
  • 11
  • 22
  • first i run react-native start but when running react-native run-android,it gets terminated after build successfull – Belle Solutions Mar 31 '19 at 15:59
  • 25
    You have to have 2 node console running simultaneously. One starts and runs the bundler, the other runs the emulator. – Nerdragen Mar 31 '19 at 16:02
  • 102
    For me, this error appears even if the bundler is started. – P.Lorand Apr 23 '19 at 08:09
  • 6
    Make sure port 8081 isn't blocked. Also, make sure that you use one terminal to start the bundler, wait for it to finish loading the dependency graph, then run react-native run-android on another terminal. – Nerdragen Apr 23 '19 at 14:16
  • @Nerdragen should i wait till the loading the dependency graph actually i got ** loading the dependency graph done.** like message on cmd – Arbaz.in Jul 23 '19 at 11:54
  • 1
    @Arbaz.in yes, you need to wait for the dependency graph to finish loading first – Nerdragen Jul 23 '19 at 12:53
  • I got loading dependency done message what us the meaning ofthat message – Arbaz.in Jul 23 '19 at 12:59
  • It means the packager has finished loading the dependency graph and you can start the emulator – Nerdragen Jul 23 '19 at 13:00
  • i started emulator the i write **react-native run-android** this command .after this command server start with 8081 port – Arbaz.in Jul 23 '19 at 13:24
  • react-native start comman results in loading dependency graph... done and doesn't say completed or anything – Vikas Pandey Aug 22 '19 at 10:41
  • When the dependency graph has finished loading, that's all it'll say. Keep that console open and start the debugger – Nerdragen Aug 22 '19 at 13:00
  • 1
    In windows it runs by itself, but on linux it doesn't, thx! Work perfect! – Adrian Serna Aug 22 '19 at 18:03
  • 1
    @Nerdragen How can I check whether port 8081 is blocked or not. – Hasnain Oct 05 '19 at 09:20
  • I tried running my code from VS Code , and I had same error . Untill I use npm start and react-native run-android , thank you – Omar Isaid Apr 25 '20 at 12:59
136

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

Saeed
  • 3,294
  • 5
  • 35
  • 52
  • What is the location of this file in react native project index.android.j – Arbaz.in Jul 24 '19 at 04:51
  • @Arbaz.in in the root directory. – Saeed Jul 24 '19 at 05:10
  • @Arbaz.in Maybe there is an `index.js` file in root directory in which case you **do not need** to rename it – Saeed Jul 24 '19 at 05:11
  • @Saeed Steps for windows ? – Hasnain Oct 05 '19 at 09:28
  • For all (Mac, Linux, Windows) – Saeed Jan 14 '20 at 06:54
  • 14
    This can only run the app for the moment but how will this enable the debugging and hot loading? this is not the perfect solution to getting this done. – buddhiv Feb 21 '20 at 06:09
  • 1
    @buddhiv Then what is the perfect solution? – Marfin. F May 05 '20 at 22:19
  • 2
    It worked fine for me. But I couldn't understand what happened. This error started to happen just because. – JmLavoier Jul 24 '20 at 03:03
  • 2
    It worked and I can debug and the hot loading works as well although as @JmLavoier said I don't know why it stopped working and why now it is working again – kingston Dec 05 '20 at 15:48
  • 2
    Now logging not works, how to start it again – Eren Tüfekçi Dec 21 '20 at 11:47
  • It worked for me and I was able to load app in Emulator but now. I am not able to build it from command line ./gradlew assembleRelease for error "> Task :app:mergeReleaseResources FAILED" – Arvind K. Jul 31 '21 at 09:50
  • Is there a way to "undo" it?? – Arvind K. Jul 31 '21 at 09:55
  • FAILURE: Build failed with an exception. * What went wrong: Could not open settings generic class cache for settings file 'C:\programming\zoomino 6\imaps-native\android\settings.gradle' (C:\Users\aseme\.gradle\caches\7.5.1\scripts\6ozn04tb0t0k7dwz97qf9fvs6). > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63 – IMPixel Jan 06 '23 at 00:22
  • for me worked better 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/` – Leffa Apr 10 '23 at 02:42
116

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 .

Shaido
  • 27,497
  • 23
  • 70
  • 73
Tua Tara
  • 1,169
  • 1
  • 7
  • 5
54

A similar issue happened with me.
Apparently Mcafee blocks 8081 port. Took me hours to figure this out.

Try running:

react-native run-android --port=1234

When app shows up with an error on emulator, get into dev settings (Ctrl+M).

Change the "Debug server host and port for device" to "localhost:1234".

Close the app and start it from the app drawer.

Azametzin
  • 5,223
  • 12
  • 28
  • 46
Naveen Kumar
  • 681
  • 4
  • 6
  • 2
    thanks for a hint, I had to open port 8081 in my firewall and it started working – ukie Jun 21 '19 at 18:09
  • I tried to hit the localhost:8081 in browser but no luck. Little research and found out that macafee has blocked that port. Folllowed your way. Started working perfectly fine. – Tushar Jajodia Jun 07 '20 at 11:36
  • I lolled about the mcaffee part, but it also worked for me. Really appreaciated.:) – Bart Jun 08 '20 at 17:26
  • This Hint was what I need (Windows 10) basically port 8081 was blocked, and once I killed all that was running on that port, my App magically started working. A usefully command was the following , which killed all processes on port 8081: **for /f "tokens=5" %a in ('netstat -aon ^| find ":8081" ^| find "LISTENING"') do taskkill /f /pid %a** – Ebe Nov 30 '20 at 14:22
  • This is what exactly seems to be happening on my system when I started with 1234 everything works fine, the exception was misleading for a while, going crazy, don't know how my day would have ended if not I land here, thank you! – Naga Feb 11 '22 at 17:25
50

For me this error was caused by an upgrade of react-native

Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

If you check out the upgrade diff you need to create a debug manifest android/app/src/debug/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>

See for more info: https://stackoverflow.com/a/50834600/1713216

https://react-native-community.github.io/upgrade-helper/

Tom
  • 12,591
  • 13
  • 72
  • 112
  • 2
    Worked for me on RN 0.61.3. – Żabojad Oct 30 '19 at 16:54
  • 4
    Unfortunately, this did not work for me. I already had this and am still getting the same error, even though the Metro Bundler is running. – Andrew Oct 31 '19 at 19:18
  • I've found I sometimes need extra overrides if I have a networkSecurityConfig defined, it seems to always be these settings causing the issues for me though. You can try removing any security config, and specify `android:usesCleartextTraffic="true"` in the main `AndroidManifest.xml` see if that works? – Tom Nov 04 '19 at 20:38
  • 1
    I have all of that settings including android:usesCleartextTraffic="true", but I still can't run app on real device. – Lucky_girl Jul 16 '20 at 12:11
  • Worked for me. To add some clarity, this was specifically a step mentioned in the RN upgrade docs: https://reactnative.dev/docs/_integration-with-exisiting-apps-java#cleartext-traffic-api-level-28 I can recommend just copying the debug AndroidManifest from the RN template project, worked a charm: https://github.com/facebook/react-native/blob/master/template/android/app/src/debug/AndroidManifest.xml – Chris Petty Dec 10 '20 at 05:02
33

You can try the following:

Add this line on your AndroidManifest.xml

<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>

EDIT: Be careful, it must be false on production for the security of your app

tinmarfrutos
  • 1,740
  • 1
  • 14
  • 23
21

just add three splash in : node_modules\metro-config\src\defaults\blacklist.js

replace this part:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];
Alireza
  • 446
  • 4
  • 15
15

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

Abolfazl Roshanzamir
  • 12,730
  • 5
  • 63
  • 79
  • 1
    12.9 also worked for me, Thanks, I had upgraded to version 12.13.x and started getting the above problem. – Tadiwanashe Dec 03 '19 at 11:59
  • Background to this answer: https://github.com/facebook/react-native/issues/26598 – Christian Davén Jan 03 '20 at 18:53
  • 1
    This worked for me, but then I got `development server returned response error code: 500`... `Metro has encountered an error: EACCESS: permission denied /tmp/metro-cache/33/....` A quick `chmod +777 /tmp -R` on my local computer solved the problem. Warning: never +777 :-D –  Aug 31 '20 at 08:24
14

In my case, the emulator's Wifi and Mobile Data was off.

chandan
  • 2,400
  • 2
  • 18
  • 23
  • this works for me. who would have thought that turning the mobile data off won't crash the app. thank you! – kohane15 Jul 27 '23 at 07:40
12

[Quick Answer]

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 1: Try to update or downgrade npm and node version.
  • 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 a yarn install you need to change the code again.

Javier C.
  • 7,859
  • 5
  • 41
  • 53
12

I've encountered the same issue while following the React Native tutorial (developing on Linux and targeting Android).

This issue helped me resolve the problem in following steps. Run following commands in the below sequence:

  1. (in project directory) mkdir android/app/src/main/assets
  2. 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
  3. react-native run-android

You can automate the above steps by placing them in scripts part of package.json like this:

"android-linux": "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 && react-native run-android"

Then you can just execute npm run android-linux from your command line every time.

cracknut
  • 301
  • 2
  • 11
  • Well sonofab*tch! This (new) project I'm on had that EXACT script (step 2) in the `package.json` but I had never needed something like it before, so I ignored it. That was a tough lesson for me to learn. – Mike S. Apr 14 '22 at 16:39
10

This worked for me after trying several ways.

In the file node_modules\metro-config\src\defaults\blacklist.js

Replace :

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

with :

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

hope this helps.

  • 2
    From the looks of it, `metro-config` used \ for paths instead of /, which this answer suggests to modify. **Do not do this**. Modifying npm packages means your whole team has to do this on their machine, in CI, in staging, in production, and every time metro-config releases an update. A better approach is to fork metro-config on GitHub, commit a fix, push and submit a PR to fix it for everyone. – Cameron Wilby Jan 05 '20 at 04:28
9

Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

This is what you need to do to get rid of this problem if you do normal run commands properly

  1. npm install
  2. react-native start
  3. react-native run-android

And modify your android manifest file like this.

<application
    android:name=".MainApplication"
    android:icon="@mipmap/ic_launcher"
    android:usesCleartextTraffic="true" // add this line with TRUE Value.
android:theme="@style/AppTheme">
8

If you are on linux open the terminal from the App root directory and run

npm start

then open another terminal window and run:

react-native run-android
Akshatha S R
  • 1,237
  • 1
  • 15
  • 30
solomon njobvu
  • 581
  • 6
  • 6
8

In my case I was trying to run the application on the emulator. But, I was getting this

enter image description here

This IP 10.0.2.2 was accessible from emulator chrome browser. The issue is that this IP is not whitelisted in Android Network Security Settings. So, whatever IP Address you are seeing here add that in below settings and you are good to go.

./android/app/src/main/AndroidManifest.xml

        <application
                android:name=".MainApplication"
+               android:usesCleartextTraffic="true"   <- Add this line
                android:allowBackup="true"
                android:label="@string/app_name"
                android:icon="@mipmap/ic_launcher"

./android/app/src/main/res/xml/network_security_config.xml
</network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.1.1</domain>
        <domain includeSubdomains="true">10.0.2.2</domain>
        <domain includeSubdomains="true">10.0.3.2</domain>
    </domain-config>
 </network-security-config>

Just replace <domain includeSubdomains="true">10.0.2.2</domain> with the IP you are shown in the error from react-native.

Jawand Singh
  • 1,929
  • 1
  • 24
  • 21
7

Like most of us I assume you are running on VSCODE. In my case, I ran

npx react-native start

from a seperate terminal

Now run npx react-native run-android from your terminal in VSCODE

ambassallo
  • 924
  • 1
  • 12
  • 27
7

A combination of 2 answers solved my problem. It was port related.

adb reverse tcp:8088 tcp:8088
react-native run-android --port=8088

By doing this, the app loaded fine of my phone connected by USB. I think my AV or Vagrant or something else in my PC was using that port.

You can change 8088 to something else if needed.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Patrick Simard
  • 2,294
  • 3
  • 24
  • 38
5

My solution to this is as below:

Start Metro server

$ react-native start

Start Android

$ react-native run-android

If see errors saying "port 8081 already in use", then you can kill that process and rerun

$ react-native start

See React Native Troubleshooting Page .

shizhen
  • 12,251
  • 9
  • 52
  • 88
5

After hours searching for a answer. The solution was to make a downgrade node to version 12.4.

In my case I realize that the error just occurs in version react native 0.60 with node version 12.6.

5

I'm sure it some combination of the other things mentioned here like allowing clear text, which I enabled for localhost. But this was the final piece in the puzzle.

project.ext.react = [
    entryFile: "index.js",

    // ADD THESE THREE

    bundleAssetName: "index.android.bundle",
    bundleInDebug: true,
    bundleInRelease: true
]

RN: 0.61.3

Max Phillips
  • 6,991
  • 9
  • 44
  • 71
  • this is what fixed it for me! I was building a variant, and needed `bundleInStaging: true` for the `staging` variant! Too bad I didn't see this answer until way later, this could have really helped me same some time! – mswieboda Dec 09 '21 at 14:58
  • could be nicer if you mentioned where this is supposed to be ie : app/build.gradle – Steve Moretz Apr 01 '22 at 18:34
4

I just want to add a non-obvious possibility not covered here. I am using @react-native-community/netinfo for detecting network changes, primarily network state. To test network-off state, the WIFI switch (on the emulator) needs to be switched off. This also effectively cuts off the bridge between the emulator and the debug environment. I had not re-enabled WIFI after my tests since i was away from the computer and promptly forgot about it when i got back.

There is a possibility that this could be the case for somebody else as well and worth checking before taking any other drastic steps.

arunmenon
  • 489
  • 3
  • 9
  • 18
4

I have also faced this issue. I resolved this by following step.

Check android sdk path in Environment Variable.

Add ANDROID_HOME = C:\Users\user_name\AppData\Local\Android\Sdk in System Variable
and C:\Users\user_name\AppData\Local\Android\Sdk\platform-tools path in System Variable

replace sharedBlacklist as below code segment,

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

in node_modules/metro-config/src/default/blacklist.js

Then run npx react-native run-android --port 9001

Krishna Jangid
  • 4,961
  • 5
  • 27
  • 33
Chanaka
  • 760
  • 1
  • 10
  • 21
4

Apparently, none of the answers fixed the issue for me. I was able to run the react-native app on emulator but the same code (even when the Server was running), gave me this error when running the app on the device.

I was able to resolve it by executing the following command in the terminal:

adb reverse tcp:8081 tcp:8081

Mahendra Liya
  • 12,912
  • 14
  • 88
  • 114
3

I was having the same trouble, the problem for me was that adb was not in the right environment path, the error is telling you metro port, while you're in the adb, ports are killed and restarted.

Add Enviroment Variable (ADB)

  1. Open environment variables
  2. Select from the second frame PATH variable and click edit option below
  3. Click on add option
  4. Submit the sdk platform tools path C:\Users\ My User \AppData\Local\Android\Sdk\platform-tools

Note: Or depending where is located adb.exe in your machine

  1. Save changes

Run android build again

$ react-native run-android

Or

$ react-native start

$ react-native run-android
3

In my case, I've set a proxy in my emulator. It works back to normal after I removing that proxy.

Benson
  • 248
  • 3
  • 15
3

possibility of this error is also the wrong path,check once

 export ANDROID_HOME=/Users/microrentindia/Library/Android/sdk/
 export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
user3143487
  • 235
  • 3
  • 7
3

Here how I solved this issue without touching the build:

1- Closed the Virtual Device

2- Tested on Physical Device --(it works)

3- Created new Virtual Device with API 30 Android 10+

4- Try again on newly created Virtual Device, and all work like a charm.

0xFK
  • 2,433
  • 32
  • 24
2

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

forestbaba
  • 189
  • 1
  • 4
2

For me this problem started with upgrading react-native. The upgrade was necessary to add 64-bit support.

Before:
-------- 
Environment:
Node: 10.15.0
npm: 6.9.0
Watchman: 4.9.0
Xcode: Not Found
Android Studio: 3.4 AI-183.6156.11.34.5692245

Packages: (wanted => installed)
react: 16.0.0-alpha.12 => 16.0.0-alpha.12
react-native: ~0.55.2 => 0.55.4
react-native-cli: 2.0.1

After:
------
info 
React Native Environment Info:
Binaries:
Node: 10.15.0
npm: 6.9.0
Watchman: 4.9.0
SDKs:
Android SDK:
API Levels: 23, 26, 27, 28
Build Tools: 27.0.3, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: /undefined - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.6 => 16.9.0 
react-native: 0.59.9 => 0.59.9 
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1

Also, One important change that I made for the upgrade was in ../android/build/build.gradle

android {
    ...
    defaultConfig {
        ...
        targetSdkVersion 28
        ...
    }
    ...
}

I had to change the targetSdkVersion from 27 to 28 following warning when I tried to upload the build(.apk) to goole play console. Little did i realise that this was the root cause of the above error for me. Immediatly answers by @tom and @tinmarfrutos made absolute sense.

I solved the problem by adding android:usesCleartextTraffic="true" to my android/app/src/debug/AndroidManifest.xml

vivekkan
  • 53
  • 1
  • 5
2

The solution that worked for me is the following:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
]; 

My code example

Jorge Santos Neill
  • 1,635
  • 13
  • 6
2

update this part in metro blacklist

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];
2

Try These steps if you have tried everything mentioned in above solutions:

  1. Create File in android/app/src/main/assets
  2. 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

  1. Now run your command to build for e.g. react-native run-android
Prayag
  • 331
  • 2
  • 9
  • Wow this helped me partialy. I was preparing my app for google play market all i did is add new assets icons for android and change target versin to 28. I had to change back to v27 version and all start working again... I dont know why react not working with sdk v28. – Michail Pidgorodetskiy Apr 28 '20 at 18:59
2

I have run into similar issue. npx react-native init creates .gitignore file which ignores <project>/android/app/src/debug folder. If you have later cloned this project, this folder would be missing. The solution is simple. In future add this line to the bottom of the .gitignore file.

!android/app/src/debug

For your current project ask the project creator to commit this folder. I have encountered this error with react native version 0.63

Jakub Orsula
  • 75
  • 2
  • 10
2
  1. In my case I just close the app form emulator

  2. Then run this again

react-native run-android

hexhad
  • 1,139
  • 12
  • 14
1

IMPORTANT - You might have many Virtual devices in your environment. Ensure if you are changing AVD you repeat the setting again.

DEBUG INFORMATION-

Incase you are experiencing above error you have to 1st verify what is running on port 8081

Quickest way to find that is using the following command in terminal

netstat -aon | findstr 8081

if that shows you something it means the port is blocked. if possible get that port unblocked.

Otherwise, you would need to change the port. The process to do that has already been mentioned in the comment above by Naveen Kumar

react-native run-android --port=9001

Ensure 9001 is not used either :)

Garg
  • 2,731
  • 2
  • 36
  • 47
TARJU
  • 1,785
  • 1
  • 14
  • 16
  • 1
    Awesome.. this worked for me. Just remember if you have a habit of starting react server using "npm start" then add " --port=9001" to your start script as well in package.json. – saurabh Jun 10 '21 at 16:44
1

By default a tiny JavaScript server called "Metro Server" runs on the port 8081.

You need to make this port available for this Server to start. So,

  1. release the port
  2. close your virtual device
  3. "react-native run-android" again.

How to release the port?

http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html

How to kill the process currently using a port on localhost in windows?

and most importantly, I upgraded my node version from 8.x to 10.x(latest), as suggested by facebook @ https://facebook.github.io/react-native/docs/getting-started

Karthik H
  • 1,267
  • 12
  • 13
1

The error message on the emulator is kind of misleading. In my case, I used a Macbook. I needed to change the permissions on android/gradlew by running $ chmod 755 ./gradlew, and then the app could be built and deployed to the android emulator.

brass monkey
  • 5,841
  • 10
  • 36
  • 61
Jane
  • 11
  • 1
1

This is caused whenever the android device cannot reach the metro server. If the above doesn't work, check to see that your android device doesn't have a proxy configured. (Settings > Proxy > No Proxy).

heneryville
  • 2,853
  • 1
  • 23
  • 30
1

This error appeared out of nowhere for me and what solved it for me was:

  1. AVD manager in Android Studio
  2. Press arrow down under Actions on your virtual device
  3. Wipe data
  4. Restart Metro
Crashtor
  • 1,249
  • 1
  • 13
  • 21
1

Run the follwoing two commands

  1. adb kill-server
  2. adb start-server

After that, run the command npm start followed by the usual green run button in Android studio.

arun8
  • 1,191
  • 2
  • 14
  • 26
1

I had try all solution below commented and answered by different people. Some Times it work but some times no one solution works for me..... best solution for this error uninstall APK from physical device and and run app once again ...its work for me 100% !!!

step 1-

Uninstall APK from physical Device

step 2-

Go to Android folder cd android

step 3-

Enter Command Gradlew Clean

step 4-

Enter Cd.. back to Project

step 4-

Run Command npx react-native run-android OR react-native run-android

Avishkar Patil
  • 220
  • 4
  • 14
1

this works for me, additionally add port number and run android

npx react-native run-android --port=8082 (maybe port number differs)
Nagaraj sk
  • 71
  • 8
0

If you are running on Linux OS,there might be case where your npm remote server is not running. Open another terminal (with project directory) and run this command sudo npm start or sudo react-native start before doing sudo react-native run-android

vicky keshri
  • 447
  • 5
  • 16
0

In Some Cases You Might Want To Close the port Of React-native bundler and Rerun the App With the same process

1.sudo kill -9 $(sudo lsof -t -i:9001)

2.npm start inside the project

3. react-native run-android
Varun Pradhan
  • 587
  • 5
  • 8
0

What worked for me was:

  1. close all consoles
  2. open a new console
  3. $ adb devices
  4. make sure you got only one devices connected
  5. $ react-native run-android
dcx86
  • 1,106
  • 1
  • 10
  • 14
0

you can also downgrade node js to version less than 12 and remove nodemodule then run npm install again

0

I did: react-native start and npx react-native run-android.

However, for Min19, (Ubuntu based) I was having the same problem until I run:

echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

From: https://reactnative.dev/docs/troubleshooting#content

At least I got the app running in my cell phone.

Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56
0

I got the same issue, after following the following steps, it got resolved the issue

  1. Clear watchman watches: watchman watch-del-all.
  2. Delete the node_modules folder: rm -rf node_modules && npm install.
  3. Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-*
  4. Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*
Srikanth Gurram
  • 1,022
  • 1
  • 10
  • 22
0

I had the same issue. But this method solved it. Go to the android folder using cd android then gradlew clean or ./gradlew clean whichever works for your os.

SulaRanawake
  • 66
  • 1
  • 7
0

Possibly your port is taken. Try running on different port:

adb reverse tcp:6666 tcp:6666
react-native run-android --port 6666

check if port you are using is free

linux:

lsof | grep LISTEN

windows:

netstat -an
arturas
  • 1,027
  • 1
  • 9
  • 26
0

Please check if the metro server is running any other ports. If any, stop all servers then restart the server, and try it again.

Abhijith Brumal
  • 1,652
  • 10
  • 14
0

Turn off proxy, if you set proxy in android studio, default use proxy

Turn off proxy

admin
  • 169
  • 1
  • 6
0

this works for me on ubuntu

  1. if you are having node version 17 first downgrade its version:- You can use n for node's version management.

this is very easy to use. $ npm install -g n

then you can show your node version: $ node -v v16.13.2

  1. create an assets folder inside root of the project:- project\android\app\src\main\assets set folder name should be assets

  2. now the final step implement the given code inside the project folder:-

$cd project /project$ 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

  1. after following all these step react-native was successfully running on my pc
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Aahad
  • 507
  • 4
  • 13
0

For M1 Chip

Verify your JAVA_HOME path, in my case for M1 chip I defined this as in .zprofile

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

then run source ~/.zprofile on terminal

It worked for me after this.

kaushal
  • 903
  • 10
  • 17
0

This could also be caused by disabling INTERNET permissions in the manifest. I have an app which does not require/use any internet and I had removed it. It's been a while since I updated this app and had forgotten all about it. Spent about an hour trying every single answer again.

Abdul Sadik Yalcin
  • 1,744
  • 2
  • 19
  • 50
0

I encountered this issue with React Native v0.69 after renaming my android package ID.

While renaming /android/app/src/debug/java/old_package_name to
/android/app/src/debug/java/new_package_name, I accidentaly moved the debug version of AndroidManifest.xml into the newly created path.

After moving it back out to /android/app/src/debug/, yarn android worked again without doing any of these other solutions. It's interesting this mistake caused this error so in case it happens to anyone else, check to make sure your files are where they are supposed to be.

Nick97832954
  • 113
  • 6
0

Try This

taskkill /F /IM node.exe

and then

npx react-native run-android
Merrin K
  • 1,602
  • 1
  • 16
  • 27
0

try this command

~/Library/Android/sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Vinnie
  • 481
  • 3
  • 3
0

If your using eas expo react native, check your package.json file to see if you installed expo-dev-client.

This was the issue for me. Installing it fixed it for me.

Ensure to prebuild after installation else likely won't work. npx expo prebuild

Alexander
  • 457
  • 1
  • 4
  • 15
0

I just made sure my phone was connected to the same internet address with my laptop, and the problem was solved. Also cd into you android folder and run ./gradlew clean

Okpo
  • 375
  • 4
  • 9
0

I found in windows 'macmnsvc.exe' was also running in port 8081

so you can change your port for android application by running

npm start -- --port=8088

in your root directory using cmd

Shubham
  • 31
  • 2
0

Non of the above solutions did not work for me on ubuntu OS, I solved it by running the following commands in order so that they run and watch on the same port:

  1. npm start --port=8081
  2. npm run-android --port=8081
Mundruku
  • 229
  • 4
  • 5
0

Issue solved at least for me.

create network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

use this config in app manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:networkSecurityConfig="@xml/network_security_config"
        ...>
        ...
    </application>
</manifest>
-4

Try the following.

  1. Remove Android and IOS folders
  2. run react-native eject
  3. run react-native run-android

Maybe after the previous steps you have executions npm start - --reset-cache

I work, I hope it helps you.

LuisO
  • 1
  • 1