繁体   English   中英

无法运行 react-native 项目

[英]Can't run react-native project

I created a react-native project with npx react-native init myApp, set up ANDROID_HOME and JAVA_HOME variables in enviroment variables, installed Android Studio, downloaded everything needed (Chocolatey, Node.js, Python 2, Openjdk11). 但是当我运行命令时

npx react-native run-android

它不会启动项目。 它会打开 android 仿真器,但我在控制台下面收到此错误。 到目前为止我尝试了什么:

在 settings.graddle 中更改 /

删除 node_modules, package.json.lock 并重新安装所有内容

开始其他项目

重新安装Android Studio

使 Android Studio 中的缓存失效

卸载并安装@react-native-community/cli-platform-android

控制台错误:

PS C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp> npx react-native run-android
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 946 file(s) to forward-jetify. Using 16 workers...
info Starting JS server...
info Installing the app...
:ReactNative:Unexpected empty result of running '[node, C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\bin.js, config]' command.
:ReactNative:Running '[node, C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\bin.js, config]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\myusername\OneDrive\Work Áreao\work\react-native\app\myApp\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 213

* What went wrong:
A problem occurred evaluating script.
> node:internal/modules/cjs/loader:936  throw err;  ^Error: Cannot find module 'C:\Users\myusername\OneDrive\ÃWork Áreao\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\bin.js'    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)    at Function.Module._load (node:internal/modules/cjs/loader:778:27)    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)   
 at node:internal/main/run_main_module:17:47 {  code: 'MODULE_NOT_FOUND',  requireStack: []}

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

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
:ReactNative:Unexpected empty result of running '[node, C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\bin.js, config]' command.
:ReactNative:Running '[node, C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\bin.js, config]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\myusername\OneDrive\Work Áreao\work\react-native\app\myApp\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 213

* What went wrong:
A problem occurred evaluating script.
> node:internal/modules/cjs/loader:936  throw err;  ^Error: Cannot find module 'C:\Users\myusername\OneDrive\ÃWork Áreao\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\bin.js'    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)    at Function.Module._load (node:internal/modules/cjs/loader:778:27)    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)   
 at node:internal/main/run_main_module:17:47 {  code: 'MODULE_NOT_FOUND',  requireStack: []}

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

    at makeError (C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\execa\index.js:174:9)
    at C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (C:\Users\myusername\OneDrive\Work Área\work\react-native\app\myApp\node_modules\@react-native-community\cli\build\index.js:192:9)  
info Run CLI with --verbose flag for more details.

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

打开 Android Studio 文件 -> 项目结构 -> Gradle 设置 -> Gradle JDK

并设置为

嵌入式 JDK

在尝试了许多其他选择之后,这对我有用。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM