'Error while executing npx react-native run-android
I am new to React native and trying to connect my android device but it is showing the following error. I have probably made some mistakes during installation. What should I do so that the emulator will start?
C:\Users\Bhavna>cd AwesomeProject
C:\Users\Bhavna\AwesomeProject>npx react-native run-android
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 4 workers...
info JS server already running.
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 FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
27 actionable tasks: 2 executed, 25 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s
error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (C:\Users\Bhavna\AwesomeProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Solution 1:[1]
You should connect a physical device or launch simulator from android studio, before running
react-native run-android
> com.android.builder.testing.api.DeviceException: No connected devices!
Solution 2:[2]
You should check if you enable the debug mode in your phone. And follow this.
export PATH=~/Library/Android/sdk/tools:$PATH
export PATH=~/Library/Android/sdk/platform-tools:$PATH
adb reverse tcp:8081 tcp:8081
adb shell input keyevent 82
The first one enables adb in your terminal. And the second onen enables 8081 port. If you run the third one then you could see the developer menu in your app.
Solution 3:[3]
I tried changing option from 'charging this device' to 'transfer files' and now it's working fine. Thank you everyone!
Solution 4:[4]
I've got this issue. Here's my solution: the path to platform-tools in the environment variable must be in PATH and not in ANDROID_HOME!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | B. Mohammad |
Solution 2 | Shing Ho Tan |
Solution 3 | Bhavana Rajput |
Solution 4 | Louis |