react-native - 运行“npx react-native run-android”时出现问题。如何解决?
问题描述
使用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```
解决方案
我认为
> compileSdkVersion is not specified.
是问题。添加
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
在 build.gradle
推荐阅读
- javascript - 当我尝试将一段 html 压缩到单独的页面并压缩它时不起作用
- python - 如何摆脱一行中的“+”?
- reactjs - 在 React Native 中为 TextInput 中的占位符提供样式
- java - Selenium chromedriver 无法点击 SVG 元素
- html - 将采用输入图像的 HTML 页面转换为采用文本的 HTML 页面
- javascript - MailApp.sendEmail 谷歌脚本函数
- oauth-2.0 - 如何使用授权码在 Postman 中模拟 oAuth 2.0 流程
- php - 是否有任何选项可以检查 API 是否需要超过 10 秒才能在 PHP 中调用?
- php - 在 woocommerce 通过空对象的情况下使用条纹进行支付测试后出错
- keras - cnn-keras fit_generator 回调中的值错误