无法在Android模拟器上运行React Native应用

时间:2020-03-23 14:19:08

标签: reactjs react-native react-native-android react-native-ios

我在运行npm run android时遇到以下错误,我正在提升本机响应,但不知道解决此问题的方法。但是当我运行npm run ios时,它在IOS上运行良好。我不知道错误是否来自模拟器

> 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

我尝试过npm run android --deviceId xxxxxxxxx,但仍然遇到相同的问题...可能是什么问题?

2 个答案:

答案 0 :(得分:0)

我有这个问题。 它似乎无法建立。请按照以下步骤解决此问题。
1-转到android目录。
2- ./gradlew installDebug --stacktrace
尝试解决发生的异常。在“原因”部分中,您可以查看更多详细信息。
构建成功后,请返回项目目录,然后尝试react-native run-android

答案 1 :(得分:0)

  1. 创建文件local.properties
  2. 将此行添加到此文件sdk.dir=C\:\\Users\\Admin\\AppData\\Local\\Android\\Sdk
  3. 最后将您的local.properties文件添加到android文件夹中
  4. 尝试react-native run-android