React native “运行时发出”;npx react本机运行android;。如何解决?

React native “运行时发出”;npx react本机运行android;。如何解决?,react-native,android-studio,build.gradle,development-environment,android-sdk-manager,React Native,Android Studio,Build.gradle,Development Environment,Android Sdk Manager,使用npx react native init AwesomeProject创建了一个项目。在另一个终端上运行npx react native run android时,我发现以下错误。我尝试在中遵循React Native CLI Quickstart。我已经分别安装了python2、openjdk8和nodejs,后来删除了它们并用chocolate重新安装。我已经重新安装了AndroidDK工具,AVD多次仍然收到相同的错误 info Running jetifier to migrate

使用
npx react native init AwesomeProject
创建了一个项目。在另一个终端上运行npx react native run android时,我发现以下错误。我尝试在中遵循React Native CLI Quickstart。我已经分别安装了python2、openjdk8和nodejs,后来删除了它们并用chocolate重新安装。我已经重新安装了AndroidDK工具,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```

确保您已在environment varailble中添加了android SDK路径”

编辑: 通过在Android studio中创建一个模拟器来确保您有一个正在运行的模拟器,或者在打开USB调试的情况下连接物理设备。

我认为

You need to set the ANDROID_HOME & JAVA_HOME in your environments variables if you are in Windows and in either the bashrc or the zshr  if you are using a Mac
 
JAVA_HOME => C:\Program Files\OpenJDK\openjdk-8u262-b10
ANDROID_HOME => C:\Users\laptopName\AppData\Local\Android\Sdk>

P.S: On Windows just enter env in the search bar and click on the first tab then click on New and add those then you are good to go.
 > compileSdkVersion is not specified.
这是个问题。 加


在build.gradle

中,您是否可以在终端中打印
$ANDROID_HOME
,并确保在更新路径后重新启动终端?回答是,确保安装了模拟器或验证,它们都是好的。我认为问题不在于env设置。模拟器设置也很好。您可以分享您在路径中添加的内容吗\Users\Raja Naveen\AppData\Local\Android\Sdk,C:\Users\Raja Naveen\AppData\Local\Android\Sdk\platform tools,C:\Users\Raja Naveen\AppData\Local\Android\Sdk\emulator,C:\Users\Raja Naveen\AppData\Local\Android\Sdk\tools,C:\Users\Raja Naveen\AppData\Local\Android\Sdk\tools\bin-这些都添加在路径中。C:\Users\Raja Naveen\AppData\Local\Android\Sdk-添加为ANDROID_Home您能在命令行中运行adb、java和javac并给出结果吗?您使用的是Mac还是Windows,项目是否在不同的操作系统中初始化?我使用Windows,我在4-5天前初始化了项目。我在cmd中运行adb、java、javac,它们显示了使用选项。尝试在构建中添加这一行。android括号中应用程序的渐变android{compileSdkVersion 27…}我在android\app\build.gradle中的上面几行中尝试了你的答案。我的版本不同,所以我尝试了compileSdkVersion 29 buildToolsVersion“29.0.2”。我尝试了两个数字,仍然存在错误。
 > compileSdkVersion is not specified.
 android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'