运行“ npx react-native run-android”时出现问题。怎么解决呢?

时间:2020-11-02 07:26:36

标签: react-native android-studio build.gradle development-environment android-sdk-manager

使用npx react-native init AwesomeProject创建了一个项目。在其他终端上运行npx react-native run-android时,出现以下错误。我尝试遵循https://reactnative.dev/docs/environment-setup中的React Native CLI快速入门。我已经分别安装了python2,openjdk8,nodejs,后来将它们删除并使用Chocolatey重新安装。我已经重新安装了AndroidSDK工具,但多次AVD仍然出现相同的错误。

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
'C:\Users\Raja' is not recognized as an internal or external command,
operable program or batch file.
info Launching emulator...
'C:\Users\Raja' is not recognized as an internal or external command,
operable program or batch file.
'C:\Users\Raja' is not recognized as an internal or external command,
operable program or batch file.

error Failed to launch emulator. Reason: Could not start emulator within 30 seconds..
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon (subsequent builds will be faster)

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\Raja Naveen\Desktop\AwesomeProject\android\app\build.gradle' line: 84

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not open dsl remapped class cache for 7f1u5qpw1jm8dwv3ri20amyrz (C:\Users\Raja Naveen\.gradle\caches\6.2\scripts-remapped\react_dysq7qqrljy3c2uubmf33rsun\7f1u5qpw1jm8dwv3ri20amyrz\dslcf39471ad2848fb82befe662c0627ed4).
   > 0

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified.

* 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 6m 33s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081```

3 个答案:

答案 0 :(得分:0)

确保已在环境变量中添加了android SDK路径”

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

编辑: 通过在Android Studio中创建一个仿真器或打开USB调试的连接的物理设备,确保您具有正在运行的仿真器。

答案 1 :(得分:0)

<h2>Different font size</h2>
<button class="first">click</button>
<button class="second">click</button>
<br>
<br>
<br>
<h2>Same font size</h2>
<button class="three">click</button>
<button class="three">click</button>

答案 2 :(得分:0)

我认为

 > compileSdkVersion is not specified.

是问题。 添加

 android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

在build.gradle