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
from terminal, I get the result/Users/John/Library/Android/sdk
. But if I add theecho $ANDROID_HOME
line to myandroid/gradlew
file, it echoes nothing. And when I run thereact-native run-android
command, the compiler complains that ANDROID_HOME is not defined. So I have to typeexport ANDROID_HOME=/Users/John/Library/Android/sdk
again, then running thereact-native run-android
command works and deploys 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.
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 :---
Click on Wipe Data option from avd Actions menu.
Now run the emulator. It should work.
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.
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.
In my case, following steps worked
Wipe data
from avd managerCold boot now