"Make sure you have an Android emulator running or a device connected" - react-native

I have a strange bug with one specific device from work.
I can run my react native app fine on emulators, and on my own device both from terminal and from android studio. But when I try to run the work device form terminal it gives me the following error:
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
Mind you, the device is recognized:
adb devices
List of devices attached
S7M7N15610000083 device
Even stranger still, I can successfully run the work device from android studio! But I want to be able to run it from the terminal using: react-native run-android. Does anyone have any idea what could cause this error?

Check permissions for android/gradlew file.
Within React native project root folder in terminal
ls -l android/gradlew
If file permission is not like below
-rwxr-xr-x 'links' 'owner' 'group' 'size' 'time' android/gradlew
links, owner, group, size, and time are replaced according to the system.
run
chmod 755 android/gradlew
within ReactNative root terminal.
Source:
https://github.com/facebook/react-native/issues/8868
Helpful resource related to permissions:
https://askubuntu.com/questions/528411/how-do-you-view-file-permissions

I also face the same issue.
I solved it by Selecting,
* Media device (MTP) once after device connected to the system USB connected.
* react-native run-android

Related

Expo Error when running Xcode iOS Simulator: No iPhone devices available in Simulator

I am trying to run a React-Native project on the xCode iOS Simulator using Expo, and I get the following errors:
There was a problem booting a device in iOS Simulator. Quit Simulator, and try again.
Error installing or running app. Error: No iPhone devices available in Simulator.
If I quit the simulator and try again I get these errors:
iOS Simulator device failed to boot. Try opening Simulator first, then running your app.
Error installing or running app. Error: Timed out waiting for iOS Simulator device to boot.
I have tried checking there are devices under the hardware tab of the Simulator.
Any advice?
I had exactly the same error message.
I decided to remove and reinstall Expo. While re-installing I noticed that some of the folders use for installation are owned by root and I have some errors while installing. I change the ownership of those folders to my username on my mac. i.e. "sudo chown -R ownerName: /usr/local/lib/node_modules"
I tried to run a new expo project again and got write access issues to a facebook watchman directory, I did the same thing I did above by granting control of this directory to my logged on account instead of the default root which is the owner of the folder at the time of the error.
I tried to run again on ios and everything now works fine
Note: I erase all the content settings in my IOS emulator before running the app on IOS. You can do this by going to the menu on simulator Hardware => Erase All Content and Settings
I had the same issue. The problem was about permissions on folders:
To install Expo on device, just run
expo client:install:ios
But you will get an error saying you have no permission on your user .expo folder, so just run with sudo:
sudo expo client:install:ios
Now it says No iPhone devices available in Simulator.. And of course, running as sudo you are not able to find the emulator running on your user. Finally I changed the folder owner to my user: gustavoeklund is my user, change to your user when running the command.
sudo chown -R gustavoeklund: /Users/gustavoeklund/.expo
Now I'm able to normally run without sudo:
expo client:install:ios

Unable to run the react-native app on emulator and on real devise at a time

When i try to run the react-native app on emulator and on real devise, getting following error,
error: more than one device/emulator
Is there any way to prevent this error?
You can run your project on one device only, so you have to choose between the emulator or your phone.
If multiple devices are running, you must specify the target device when you issue the adb command.
Although, you can switch between them with a simple command.

emulator-5554 unauthorized for adb devices

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.
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
Open an Android Virtual Device Manager.
Create a new Virtual Device.
Select any Hardware you want.
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)
Done!
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 :---
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.
Click on Wipe Data option from avd Actions menu.
Now run the emulator. It should work.
create new Virtual Device, and make sure you choose Google API's.
run the new device!. this should work
In my case, following steps worked
Wipe data from avd manager
Cold boot now
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:
Make sure the USB debugging is turned ON in Dev setting
Revoke the USB debugging authorizations
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!
Power off the emulator
In 'Your Virtual Devices' in Android Studio, click the down arrow in Actions > Select 'Cold Boot Now'
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!
I run adb kill-server and adb devices.
the device will back again.
for Emulator, the default settings is debug enabled
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.
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.
I had to create a new emulator with Google Api. Wiping data didn't work for me.
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
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.
Deleting emulator and creating it again helped me on Ubuntu
I solved Problem
add ANDROID_SDK_HOME to environment variable
ANDROID_SDK_HOME = D:\sdk
and unplug device
and use new cmd

react-native run-android fails, could not install app

I m having a problem when I try to run my react-native application in my Android Device. The device is connected even when I make sure that it is.
adb devices
List of devices attached
HMNBBCE6A2826109 device
Device: Huawei Y2
Android Version: 5.1
Debug mode: enbaled
the server is running.
When i run
react-native run-android
I get this error
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 had the same problem with my linux laptop.
I ran this inside my app root folder and worked:
chmod 755 android/gradlew
You have to give permission on the android/gradlew.
I found the answer on this github issue
And you must also do this:
Click here to see the all article on the react-native docs page (the place where i get this information).
Configure the ANDROID_HOME environment variable
The React Native tools require some environment variables to be set up in order to build apps with native code.
Add the following lines to your $HOME/.bash_profile config file:
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
.bash_profile is specific to bash. If you're using another shell, you will need to edit the appropriate shell-specific config file.
npx #react-native-community/cli doctor
This command checks your environment and displays a report of the status of react-native installation. Check the output carefully for other software you might need to install
I've been struggling with this for a while and in my case (using Windows 10) the solution was to install Java JRE and JDK even though I was already set up with Android Studio.
The problem got clearer when I created a new empty project with create-react-native-app Example and ran it with react-native run-android. The error then complained about JAVA_HOME variable.
Another good tip is to open up your project (located under "android"-folder in your react native project) in Android Studio and see if it compiles.
Good luck!
Try the command.
adb devices
See if there is any devices listed.
If so check the local.properties file inside android folder and check the sdk defined is correct.
if there is no local.properties files. add a new file named local.properties with the following content
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu May 25 18:29:08 IST 2017
sdk.dir=path to sdk
This command will also help
adb reverse tcp:8081 tcp:8081

React Native Android Run

I am just starting with react native. I created my first app using React Native CLI. It was created without any errors. When I am trying to react-native run-android It ends up with this error as shown.
1) Run command " adb devices "
It will let you know if any device is connected or not
2) Try running by setting the Environment variable and proxy commands.
Follow this link: http://facebook.github.io/react-native/releases/0.38/docs/getting-started.html#content
first Start the android emulator.
From your react native folder run:
cd android && gradlew clean
THEN
cd .. && react-native run-android
Make sure you have your device connected to your computer, you can check that by running:
adb devices
if it's not connected, in your phone go to: settings > Developer Options > (enable) USB debugging.
Else if you want to run it from an emulator you will need to either install Genymotion, or AndroidStudio.
1) Run command adb devices to list all connected devices.
2) Then run command emulator #YOUR_DEVICE_NAME.
3) If adb devices will not show any devices then follow this link
http://facebook.github.io/react-native/releases/0.38/docs/getting-started.html#content
Have an android phone attached to your computer via USB cable and enable USB Debugging in the developer options. To get to the developer options open your About Phone and tap the version number several times.
Once it is in USB Debugging mode, run adb devices and a prompt will show up on your phone. Accept it and you should be good to go.
Another problem I had was I needed to path my SDK location, if you run into that then this will help: React Native android build failed. SDK location not found