51

I am trying to run a react-native app on android emulator, but I am getting an error like

Error calling Appregistry.runApplication

AVD: 'Nexus_5X_API_23(AVD) - 6.0 OS:Windows 10

enter image description here

Please help on this?

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
Gopesh
  • 3,882
  • 11
  • 37
  • 52

13 Answers13

37

I had almost the same problem you currently have a few days ago. For me it was a real device.

From all my research, the solution that worked for me is the following :

When you launch your app by typing react-native run-android, the error appears.

So, reach your directory containing "adb.exe" ( for me it was C:\Users\username\AppData\Local\Android\Sdk\platform-tools\ )

open a terminal from here. And type adb reverse tcp:8081 tcp:8081

Then, by reloading the app on the phone, it should work.

I hope this will help you !! ( if not, shame on me )

Cheers ;)

EDIT :

I've find a more convenient solution to solve this problem.

When you launch your "react-native run-android" you might have a comment saying "adb is not recognized as internal or external command..."

Well, instead of manually using the adb command, you can add an environment variable leading to the adb.exe.

Just get to the "Control Panel" > "System and Security" > "System" > "Advanced System Settings".

From here, click on "Environment Variables". Search for the "Path" variable in the "System Variables" section. Click on it and press the "Edit" button.

There you can add a new path to this variable. Just click the "New" button and write the adb.exe path. For exemple C:\Users\username\AppData\Local\Android\Sdk\platform-tools\

(For the oldest versions of Windows, you'll have to add ";C:\Users\username\AppData\Local\Android\Sdk\platform-tools\" to the content.)

This is it, now the adb reverse tcp:8081 tcp:8081 command will be ran automatically upon building.

Hope this will even more helps you !

Swainge
  • 371
  • 2
  • 4
  • I am trying to run the app in emulator – Gopesh May 04 '17 at 17:57
  • Yeah but as it seems to be the same error, it might be the same solution. – Swainge May 04 '17 at 18:01
  • Well, sorry then, hope you'll find the solution after all :) – Swainge May 04 '17 at 18:03
  • Worked for me when using a real device, thanks! I have no idea what this command does, though. Care to elaborate? – Ryan Pergent May 16 '17 at 15:43
  • 2
    The issue was probably caused due to the phone unable to reach the debugging service on port 8081 of the computer as they are on different networks (LTE vs WiFi for instance), and the adb reverse command redirects the traffic from phone to computer. – aakath May 17 '17 at 05:36
26

I had the same issue, my fix was to run

$ react-native start

in the background then run

$ react-native run-android
dudasaus
  • 651
  • 6
  • 6
  • 1
    It works for me. I'm using ubuntu 16.04. I run the start command in a terminal and the run-android in another. – Ibanêz May 30 '17 at 02:29
  • My Problem solved . Working perfectly . In One tab of terminal run command : react-native start and in other tab run command: react-native run-android – rahul sharma Jun 06 '17 at 09:59
17

According to me this error comes when:

1) You did not run the packager at the right place i.e, you hit the wrong folder to run react-native packager so just navigate to your project's directory and run react-native start.

2) when you code something wrong with respect to Appregistry module.

3) Shutdown everything Xcode, packager, simulator etc and restart it again.

4) From the error one thing strikes in my mind is the name of the module

AppRegistry.registerComponent('AppName', () => componentName)

matches with the @"AppName" on your AppDelegate.m on the call for

[[RCTRootView alloc] initWithBundleUrl:...
                            moduleName:@"AppName"
                         launchOptions:...

5) As we are using react's component so we need to give the first character of our class name with caps on.

6) Let's see what's wrong in index.android.js and index.ios.js

Cheers :)

Codesingh
  • 3,316
  • 1
  • 11
  • 18
  • @Codesingh Thanks for the reply.I checked everything as your comments.But it is not working.I am getting the same error. My index.android.js file is https://gist.github.com/GopeshMedayil/eab9ba6c3b31c3798eb083b0cb0ccc93 – Gopesh May 03 '17 at 16:26
  • 1
    Your class name does not start with capital letter so make it correct may be that would work.. – Codesingh May 03 '17 at 17:16
  • I have updated it with capital letters but of no use.Updated gist https://gist.github.com/GopeshMedayil/eab9ba6c3b31c3798eb083b0cb0ccc93 – Gopesh May 03 '17 at 17:46
  • package.json https://gist.github.com/GopeshMedayil/936d25c0a3afd09aded07300ce6707e8 – Gopesh May 03 '17 at 18:07
  • can you please tell me that from where are you running the packager ? – Codesingh May 03 '17 at 18:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143336/discussion-between-gopesh-and-codesingh). – Gopesh May 04 '17 at 02:57
  • now working all the above steps for me. I m on Ubuntu machine. Tried hard to install every thing from scratch... but nothing working – Anurag Singh May 07 '17 at 09:44
  • 1
    `react-native start` helped in my case by showing what the actual error was (`ENOSPC`), which I've then fixed [like this](http://stackoverflow.com/a/32600959/561309). Then I had to re-run `react-native run-android` a few times, then `react-native start` in a different terminal and eventually it worked. – laurent May 09 '17 at 11:43
  • tanks, i run react-native start and react-native run-android in same time but diferents terminals, are work fine!!!! – RBoschini May 21 '17 at 02:04
2

Finally, I got it working.I created a new AVD

Nexus6 API 23

.Earlier I was trying with Nexus5x API 23.Thanks all

Gopesh
  • 3,882
  • 11
  • 37
  • 52
  • I have the same problem with Nexus6 API 23 and i have fixed it like this – Tung Vo Jun 02 '17 at 02:28
  • Hello. I know this is an old question but I have this same issue. Can you kindly explain how this solved the problem – Emmac Dec 10 '18 at 22:55
2

I had same problem. It occurs that McAffee was on port 8081 and block packager. My solution:

react-native start --port your_port

In android emulator, Command + M show dev menu, click on "Dev Settings" and then click on "Debug server host and port" and set it to your_ip:your_port.

Then

react-native run-android
Mr Jedi
  • 33,658
  • 8
  • 30
  • 40
2

In my case (after, of course, going through everything I could find here and elsewhere), I realized I had turned my WiFi off on my phone...doesn't work like that! Hope it helps someone

kwishnu
  • 1,730
  • 19
  • 17
1

I had the same issue and was able to resolve it by setting my local computer as the debug server in the android emulator. Open the android emulator, Command + M to bring up a menu, then click on "Dev Settings" and then click on "Debug server host and port" and set it to 127.0.0.1:8081. Then from within you project directory run react-native run-android. I hope this helps.

sjc42002
  • 454
  • 3
  • 7
1

Make sure that port 8081 is available. In my case One of my services is running on Port 8081(tomcat webserver).

Vino
  • 2,807
  • 1
  • 26
  • 22
0

I was having the exact same issue (because this is a very generic message) but the problem was different. In my case it was a newly created project, the emulator wasn't working but a real device did work.

My problem was the limit of watchers inotify can handle on Linux by default, which is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes back to applications and it's widely used, including android studio and react native; by the time I was trying to execute react-native run-android all of the watchers were allocated on my system, causing the process to fail on this same message.

To change the max amount of watchers inotify can handle, you need to edit the file sysctl.conf, which will be usually located at /etc/sysctl.conf or /etc/sysctl.d/custom_name.conf and add the following line:

 fs.inotify.max_user_watches = 5242881

After writing the file you need to execute sysctl -p filename.conf where 'filename.conf' is the path and name wherever you saved the .conf file for sysctl. Once changes are applied everything should work as expected.

0

I too had the same problem. I solved the problem to run on real device.

As told by Mr Jedi, McAffee blocked the port 8081. So I have modified Project-Folder>\node_modules\react-native\local-cli\runAndroid\runAndroid.js file's function from

function tryRunAdbReverse(device) {
   try {
     const adbPath = getAdbPath();
     const adbArgs = ['reverse', 'tcp:8081', 'tcp:8081'];

to

function tryRunAdbReverse(device) {
   try {
     const adbPath = getAdbPath();
     const adbArgs = ['reverse', 'tcp:8081', 'tcp:3040'];

and started the application on

      react-native start --port 3040
Ramesh K
  • 77
  • 1
  • 6
0

For me I just needed to add the platform tools to my Path environment variable so that react-native can start the adb server.

I was getting:

'adb' is not recognized as an internal tool or program

To fix this I added the following to my Path environment variable.

C:\Users\<Username>\AppData\Local\Adnroid\sdk\platform-tools

Then running react-native run-android worked!

Chase
  • 9,289
  • 5
  • 51
  • 77
0

I know this question has been given so many answers but, I think it's worth it adding my solution, hope this helps someone out there.

In my case the problem was from my virtual machine, although I didn't investigate but by creating a new virtual device the app ran smoothly with no problem.

So just create a new virtual device. :)

Daniel Barde
  • 2,603
  • 5
  • 31
  • 40
0

I searched for a solution for my registry error for a week and tried all these solutions, and all that was missing was I needed to add in my app.json file under expo:

    "platforms": [
      "ios",
      "android",
      "web"
    ],

So, if all else fails, try to add this into your expo.

Marvin
  • 853
  • 2
  • 14
  • 38