React Native: react-native run-android is not starting Android emulator - android

I am starting to build an Android application using React Native. But when I tried to run the application using "react-native run-android" command, it runs into a problem. This is what I have done so far.
I installed the react-native command line running the following commands
npm install -g react-native-cli
Then I created the react-native project running the following command.
react-native init {ProjectName}
At this point, I already have the Andriod Studio installed I have been doing the native Android development. So, I opened the Android Studio and started an emulator.
Then within the React Native project, I run the following command to start the project.
react-native run-android
Then I got the following error.
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 903 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
'adb' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Pixel_XL_API_30_2(AVD) - 11' for app:debug
Installed on 1 device.
BUILD SUCCESSFUL in 6s
29 actionable tasks: 2 executed, 27 up-to-date
info Connecting to the development server...
warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
info Starting the app...
'adb' is not recognized as an internal or external command,
operable program or batch file.
error Failed to start the app.
Error: Command failed: adb shell am start -n com.testreactnative/com.testreactnative.MainActivity
In an attempt to fix that, I added the following environment user variables pointing to the right location.
JAVA_HOME: C:\Program Files\Android\Android Studio\jre\jre
ANDROID_HOME: C:\AndroidSDK
Then I tried running the command again. It is still throwing the same error. What's wrong with my configuration and how can I fix it?

You see this error in console that says 'adb' is not recognized as an internal or external command,
This means that adb path is not added in Environment Variables
My adb path is = C:\Users\karti\AppData\Local\Android\Sdk\platform-tools
Find yours and add it to Path in Environment Variables

Related

How to fix "Error spawn Unknown system error -8" in react native

I have that weird error when running "npx react-native run-android" that is only occuring in a specific react native project only on my Macbook with android simulator. Other RN apps are running fine on my mac with android.
On a windows pc this specific RN app is also working fine.
Error: spawn Unknown system error -8
at ChildProcess.spawn (node:internal/child_process:413:11)
at Object.spawn (node:child_process:743:9)
at module.exports (/Users/hannes/Projects/test2/mapp/native-frame/node_modules/#react-native-community/cli-platform-android/node_modules/execa/index.js:205:26)
I tried the following things:
deleting package-lock.json
rm -r node_modules + gradlew clean (in android folder)
creating a new virtual device in android studio with API level according to build.gradle
upgrading node to 18.8.0
upgrading npm to 8.18.0
npm cache clean –force
Somebody any ideas?
After using "run-ios" in the meantime I had to face the problem again and found a solution.
npx react-native run-android
this line is using the port 8081 and my macbook did sometimes use this port for another service
lsof -i tcp:8081
this command showed the process that was running
COMMAND PID FD DEVICE SIZE/OFF NODE NAME
node 44492 24u 0t0 TCP *:sunproxyadmin (LISTEN)
I terminated this process but still got the error message.
So I called the gradle command for building and installing the app myself.
cd android && ./gradlew app:installDebug -PreactNativeDevServerPort=8081
This worked, the app got build and installed on my android device but I got multiple error messages in the android studio run console starting with:
Could not find generated setter for class
this error was also addressed on GitHub and Stackoverflow
So building and installing the app in production mode solved the problem for me.
./gradlew app:installRelease

react-native - 'adb' is not recognized as an internal or external command

This is my first react native setup. I started to build with react-native run android and got BUILD SUCCESSFUL in 4m 7s message.
Then the CLI script tried:
info Connecting to the development server...
warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
info Starting the app...
'adb' is not recognized as an internal or external command,
operable program or batch file.
error Failed to start the app.
Error: Command failed: adb shell am start -n com.notez/com.notez.MainActivity
at makeError (S:\Projects (my)\notez\node_modules\execa\index.js:174:9)
at Function.module.exports.sync (S:\Projects (my)\notez\node_modules\execa\index.js:338:15)
But I had settled everything up. ADB and SDK paths are defined in my OS ENV config.
So I tried to execute the failed code above on another console:
adb shell am start -n com.notez/com.notez.MainActivity
Then it worked! How can I define the 'adb' as an internal or external command as the error refers?
I changed the enviroment variable ANDROID_HOME value from C:\Users\User\AppData\Local\Android\Sdk\ to C:\Users\User\AppData\Local\Android\Sdk\platform-tools\ and it worked...

Not able to run android emulator (android-studio) with react-native

I am just starting to create a new react-native project and I followed the steps exactly as mentioned in setting-up environment for react-native.
My development OS: Mac; My target OS: Android
I created a local.properties file in my project/android directory which mentions sdk path. I have the android emulator up and running, then I do yarn react-native start, and in another terminal window, yarn react-native run:android but I get the following error:
BUILD SUCCESSFUL in 28s
27 actionable tasks: 27 executed
info Connecting to the development server...
warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
info Starting the app...
error Failed to start the app. Run CLI with --verbose flag for more details.
Error: spawnSync adb ENOENT
at Object.spawnSync (internal/child_process.js:1066:20)
error Command failed with exit code 1.
yarn react-native run:ios command runs perfectly alright.
Could anyone help with this please? I have tried the various different suggestions mentioned in this stackoverflow question but no luck.

Can't able to run react native application on android device

Im Using MacBook Pro.. Im New To React Native.. After Creating An Project Im Running On iOS Device It's Running.. At The Same Time While I'm Running On Android Device Means Im Getting This Error.. Any One Please Help Me To Resolve This Error.. Im Using Visual Studio Code IDE For React Native Application
Thanks In Advance..
Error Details :
[Info] local.properties file doesn't exist. Using Android SDK location from PATH.
[Info] Starting React Native Packager.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 8 workers...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
FAILURE: Build failed with an exception.
* Where:
Settings file '/Users/manikandan/AwesomeProject/android/settings.gradle'
* What went wrong:
Could not compile settings file '/Users/manikandan/AwesomeProject/android/settings.gradle'.
startup failed:
General error during semantic analysis: Unsupported class file major version 57
So you have two errors to fix here as your error log
local.properties file doesn't exist.
Failed to launch the emulator
local.properties file issue fixing
Open your react native project android folder using Android Studio.
Wait for gradle sync and clean the project and rebuild it using Android Studio
After that make sure you have local.properties file is been created inside android folder
If not try these steps to make local.properties file manually
Right click top level of project and Create new file 'local.properties' then add: sdk.dir=/Users/<YourUsername>/Library/Android/sdk
Clean and build
Before running your react native project on android make sure you have turn on the Android Emulator by AVD Manager in Android Studio
If you have not create any emulators then try this link - I have posted full answer on how to make Android Emulator -
React native failed to launch emulator
EDIT :
For adb error you need to install adb drivers on you Mac
Follow these steps
First install Homebrew using this command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
or this command
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After that install adb using homebrew
brew cask install android-platform-tools
Try to re run

React-native does not find Genymotion

I installed android studio, I configured the environment variables and everything, I installed genymotion and created a device, but running the react-native run-android in the project folder occurs the following error:
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/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.
please help me in this problem. React-native does not find Genymotion disositivo, in this link has more details: https://pt.stackoverflow.com/questions/382115/react-native-n%C3%A3o-reconhece-genymotion
It tries to connect the emulator to the ADB, by the IP of the device. To check the IP of the device, simply click on an emulator window, the IP address is in the title of the window.
No terminal will run the command:
$ adb connect ip_of_your_emulator:5555
Soon after, run:
$ adb devices
If the name of your file appears in the list, your emulator has been connected successfully!
With the emulator open, simply run the native run-android in the folder of your project.
I've had the same problem earlier this month. As far as I can tell the newer versions of Genymotion don't register on adb devices, a user in the Expo forums speculates it's because they have a paywall now.
I recommend switching to Android Studio, that's what I did to solve my problem.
I ran react-native with the --verbose flag, and got the following error:
...
error Failed to install the app. Make sure you have the Android development
environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
...
So, I gave permissions to the android/gradlew folder as follows:
chmod 755 android/gradlew
But then, I got an error regarding Google Play Licenses:
error Failed to install the app. Please accept all necessary Android SDK
licenses using Android SDK Manager: "$ANDROID_HOME/tools/bin/sdkmanager --licenses".
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
So yeah, pretty the solution was:
Downloading Android Studio with its own SDK
Change the env variabe ANDROID_HOME to the one installed with Android Studio
Installing Google Play Licensing Library (In Android Studio, go to Settings>SDK Manager>SDK Tools, select Google Play License Library and then install)

Categories

Resources