32

I'm trying to get my react-native project to run on an android emulator while on a Mac operating system. It worked fine on my windows.

On my Mac, I go to terminal and type react-native run-android and I get the error message:

$ react-native run-android
Scanning 616 folders for symlinks in /Users/John/Documents/myreactnativeproject/node_modules (17ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

I type adb devices and I see

List of devices attached
emulator-5554   unauthorized

I go into the settings of my android emulator, I go to Settings Build Number to tap it several times to enable Developer options. In developer options, I enabled USB debugging, disabled Verify apps over USB, and left everything else as default. I shut down my android studio and emulator, restarted it. But still, the same issues mentioned above.

What am I doing wrong?


EDIT

I just connected my android phone to my Mac. When I run adb devices, I see this result

List of devices attached
YLEDU16B18004313    device

But when I run react-native run-android, I get the same error as above. So maybe there is something wrong with my react-native set up instead?


EDIT 2

I was able to deploy the app to my android phone by adding these extra steps

  • chmod 755 android/gradlew

  • For some reason, when I type echo $ANDROID_HOME into the terminal, I get the result /Users/John/Library/Android/sdk. But if I add the echo $ANDROID_HOME line to my android/gradlew file, it echoes nothing. And when I run the react-native run-android command, the compiler complains that ANDROID_HOME is not defined. So I have to type export ANDROID_HOME=/Users/John/Library/Android/sdk again, then running the react-native run-android command works and deploys it to my phone.

However, my emulator still doesn't work. The new error message I get is that Skipping device 'emulator-5554' (emulator-5554): Device is UNAUTHORIZED,.

But at least I have a temporary solution, and to debug with my phone.


EDIT 3

I got rid of the emulator 5554 unauthorized error by going into my Android Virtual Devices and deleting the virtual device. Then I re-installed it. And now my adb devices shows emulator 5554 device. And I am not able to deploy the app to my emulator.

First Arachne
  • 786
  • 1
  • 8
  • 18
John
  • 32,403
  • 80
  • 251
  • 422
  • Can you add the complete error message please? There might be another reason since it says _"read the error above for details"_ – bennygenel Oct 23 '17 at 21:00
  • @bennygenel ok I've put in all the error messages that I received right after the `react-native run-android` command. I don't think there's anything useful there – John Oct 23 '17 at 21:16
  • Does the react packager start before the error? – bennygenel Oct 23 '17 at 21:19
  • @bennygenel it says `React packager ready. Loading dependency graph, done.` – John Oct 23 '17 at 21:20
  • I just tried to be sure, I created a new project and run `react-native run-android` without starting any emulators. Command goes through all the building stages and then gives an error about the not connected emulator. If you moved your android files from windows there might be some conflict that cause the problem. Did you try running `cd android && ./gradlew clean`? – bennygenel Oct 23 '17 at 21:25
  • @bennygenel I get permission denied when I ran the `./gradlew clean`. So then I tried `sudo ./gradlew clean` and I get this error `./gradlew: command not found` – John Oct 23 '17 at 21:29
  • @bennygenel hold on, I just chmod 755 the gradlew, now it's doing something – John Oct 23 '17 at 21:31
  • Even thought if it solves the problem you shouldn't be needing to do this. There might be some problem with your initial installment but I'm not sure what is it. – bennygenel Oct 23 '17 at 21:32
  • When you run `react-native run-android` it tries to run `(cd android && ./gradlew installDebug)` and it might be also getting `permission denied` error and can't complete the command. – bennygenel Oct 23 '17 at 21:35
  • @bennygenel ok interesting. Yes now I get a different issue saying ANDROID_HOME isn't defined. But from my terminal if I type `echo $ANDROID_HOME` I see the value `/Users/John/Library/Android/sdk`. And I confirmed that this path actually exists. – John Oct 23 '17 at 21:39
  • I'm not that good with linux or mac but can it be another permission issue like can't even get the variables? – bennygenel Oct 23 '17 at 21:42
  • Can I suggest you to try something? Can you run the app from Android Studio and not from the terminal command? If running from Android Studio doesn't start the packager you can start it with `react-native start` and then run the app. – bennygenel Oct 23 '17 at 21:43
  • @bennygenel OK, I got things to deploy to my phone. Emulator continues to be a problem. I added an Edit 2 explaining how I got things to work. – John Oct 23 '17 at 22:02
  • 1
    I'm glad that you found a temp solution but I still think that something is wrong in your installation. Creating a new project with the same version of react-native that you are using and testing if its gonna start from the command right away without any change might help to see if the problem is with your project or your os or something else. – bennygenel Oct 23 '17 at 22:06
  • 1
    @bennygenel ok I got rid of the `emulator 5554 unauthorized` message and now it shows `emulator 5554 device`, and it can now accept the react-native build. Everything works now! I explain in EDIT 3. – John Oct 25 '17 at 15:01

13 Answers13

65

In my case, Create a Virtual Device with Google APIs Image, not Google Play Image worked for me.

The problem occurs the only emulator that runs on Android Pie others don't.

In Android Studio

  1. Open an Android Virtual Device Manager.
  2. Create a new Virtual Device.
  3. Select any Hardware you want.
  4. Select any System Image which the Target is "(Google APIs)" not "(Google Play)" (If you don't found. Try to look at "x86 Images" tab or "Other Images" tab)
  5. Done!
user8637708
  • 3,303
  • 2
  • 13
  • 15
47

Android emulators have by default "Usb Debugging" in settings. You just need to wipe the data of the emulator. Do the following steps. It will work :---

  1. Close the emulator and run the command adb kill-server in the command prompt. If adb is not set in you path then you might run this command from directory where adb is present.
  2. Click on Wipe Data option from avd Actions menu. enter image description here

  3. Now run the emulator. It should work.

srs
  • 2,521
  • 16
  • 16
24

create new Virtual Device, and make sure you choose Google API's. enter image description here

run the new device!. this should work

enter image description here

Mang Ndie
  • 278
  • 3
  • 6
13

In my case, following steps worked

  1. Wipe data from avd manager
  2. Cold boot now
Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
7

I managed to authenticate the adb on a Pixel 2, Android 9.0 (Google Play), API 28, x86_64 virtual device (Intel HAXM). The problem should be related to the Extended Controls (the 3 dots bottom icon menu, when the virtual device is booted), the Google Play menu, that is checking the version of the Google Play services. When adb is not 'unauthorized', this page is displaying the correct version, and the Update button opens inside the phone the Play Store with the Play Services app, so you can update it.

The steps I took to be able to authenticate are:

  1. Make sure the USB debugging is turned ON in Dev setting
  2. Revoke the USB debugging authorizations
  3. Make sure the Extended Controls > Settings > Advanced > Open GL options are set to the: 'Desktop native OpenGL' and 'Renderer maximum (up to OpenGL ES 3.1)', so the emulator interface, animations, etc, are fast!
  4. Power off the emulator
  5. In 'Your Virtual Devices' in Android Studio, click the down arrow in Actions > Select 'Cold Boot Now'
  6. When the device boot, you have to be fast, the dialog to remember and accept the USB connection will show and disappear for like less than 1 second (again I guess related to some automation scripts kicking, idn).

If you manage to click the 'remember' and 'ok' checkbox and button before the dialog disappears, you are done. Else you have to Power Off and Cold Boot again.

After that, don't wipe your emulator, else you'll have to do that insane race clicking again!

Milen Boev
  • 611
  • 6
  • 4
  • 2
    I'm having the same issue, with the same system image... the "authorize" screen appears after the cold boot, but lasts less than a second and then disappears... will try to find a way to it to reappear. Thanks, by the way! – Fabio Mar 27 '19 at 21:07
4

I run adb kill-server and adb devices. the device will back again. for Emulator, the default settings is debug enabled

Jesse
  • 517
  • 5
  • 24
3

Creating an emulator with graphics set to "Software - GLES 2.0" worked for me (Nexus 6 image).

I was initially using a Nexus 5X image which didn't allow me to select the graphics option.

NOTE: I went through the steps mentioned in EDIT 2 and EDIT 3 by the OP before doing this.

AndyFaizan
  • 1,833
  • 21
  • 30
2

2022 answer

What a shame of thread: so many "answers", comments and upvotes and none worked. Nobody simply mentioned that the "adb unauthorized" is caused by the adb keys stored in ~/.android/adbkey and ~/.android/adbkey.pub After deleting and recreating them, the problem was solved.

Credit: Android Emulator Unauthorized

John Doe
  • 936
  • 7
  • 15
1

This can happen if USB debugging is not enabled on the emulator device.

Go to the emulated device, enable the Developer options and enable USB debugging.

enable USB debugging

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
mangei
  • 747
  • 7
  • 16
  • It hasn't worked for me for years, but on API 29 emulator I created an `avd` from `Google APIs` image, like in answers above. – CoolMind Aug 08 '19 at 08:50
1

I had to create a new emulator with Google Api. Wiping data didn't work for me.

kapil
  • 1,710
  • 1
  • 15
  • 12
0

I got my mac system to deploy a react-native build to my physical phone by following Edit 2 in the question.

I got my mac system to deploy a react-native build to my emulator by following Edit 3 in the question.

I think the issue was generally caused by moving my project from a Windows dev area to Mac dev area. Then probably a combination of different issues happened that cause builds to fail for each situation.

John
  • 32,403
  • 80
  • 251
  • 422
0

Deleting emulator and creating it again helped me on Ubuntu

Maksim Turaev
  • 4,115
  • 1
  • 29
  • 42
0

I solved Problem

add ANDROID_SDK_HOME to environment variable

ANDROID_SDK_HOME  = D:\sdk

and unplug device

and use new cmd

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
AliTN
  • 96
  • 5