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 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 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.
react-native run-android
command. I don't think there's anything useful there – PhilosophicalReact packager ready. Loading dependency graph, done.
– Philosophicalreact-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 runningcd android && ./gradlew clean
? – Demmy./gradlew clean
. So then I triedsudo ./gradlew clean
and I get this error./gradlew: command not found
– Philosophicalreact-native run-android
it tries to run(cd android && ./gradlew installDebug)
and it might be also gettingpermission denied
error and can't complete the command. – Demmyecho $ANDROID_HOME
I see the value/Users/John/Library/Android/sdk
. And I confirmed that this path actually exists. – Philosophicalreact-native start
and then run the app. – Demmyemulator 5554 unauthorized
message and now it showsemulator 5554 device
, and it can now accept the react-native build. Everything works now! I explain in EDIT 3. – Philosophical