Cannot run react native app on android emulator

Viewed 2722

I have been having this error below when I run npm run android I am leveling up on react native and do not know the way to solve this problem. but it works fine on IOS when i run npm run ios. I don't know if the error is from the emulator

> react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1757 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :react-native-select-contact
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.2.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '27.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :app:installDebug FAILED
[EmulatorConsole]: Failed to start Emulator console for 5554
01:28:40 V/ddms: execute: running am get-config
01:28:40 V/ddms: Got reply 'FAIL', diag='closed'
01:28:40 E/ddms: ADB rejected shell command (am get-config): closed
01:28:40 V/ddms: execute: returning

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
281 actionable tasks: 2 executed, 279 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.AdbCommandRejectedException: closed

* 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 28s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew 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: com.android.ddmlib.AdbCommandRejectedException: closed

* 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 28s

    at checkExecSyncError (child_process.js:607:13)
    at execFileSync (child_process.js:627:13)
    at runOnAllDevices (/Users/comname/Documents/Test/newapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at buildAndRun (/Users/comname/Documents/Test/newapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
    at then.result (/Users/comname/Documents/Test/newapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! memong@0.0.1 android: `react-native run-android`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the memong@0.0.1 android script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/comname/.npm/_logs/2020-03-23T12_28_41_531Z-debug.log

I tried npm run android --deviceId xxxxxxxxx but I still have the same issue... what could be the problem?

2 Answers

I have this problem. It seems to have failed to build. Follow these steps to resolve this issue.
1- go to the android directory.
2- ./gradlew installDebug --stacktrace
try to resolve the exception that occurred. In the "caused by" section, you can see more details.
After the built was successful, go back to the project directory, and try react-native run-android.

  1. Create file local.properties
  2. Add this line to this file sdk.dir=C\:\\Users\\Admin\\AppData\\Local\\Android\\Sdk
  3. Finally add your local.properties file inside android folder
  4. Try react-native run-android
Related