Tterm'反应原生'运行react-native运行android时无法识别

时间:2018-02-09 11:21:29

标签: react-native react-native-android

我需要帮助构建我的react-native项目。我尝试过react-native run-android但是我收到以下错误:

react-native : The term 'react-native' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ react-native run android
+ ~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (react-native:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

2 个答案:

答案 0 :(得分:0)

Iyayi Kelvin

您将需要Node,React Native命令行界面,JDK和Android Studio。

我以为你有, 开发操作系统:Linux,目标操作系统:Android

<强>节点 https://nodejs.org/en/download/package-manager/

React Native CLI

npm install -g react-native-cli

Java开发工具包 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Android开发环境 https://developer.android.com/studio/index.html

守望者(可选) https://facebook.github.io/watchman/docs/install.html#buildinstall

创建新应用

$ react-native init AwesomeProject

$ cd AwesomeProject

$ react-native run-android

注意: 如果你得到如下错误: "unable to load scripts from assets 'index.android.bundle' on real device"

然后, (如果没有创建那么)创建目录为android/app/src/main/assets

旧反应下面的原生版本&lt; 0.46

$ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

然后,

$ react-native run-android

答案 1 :(得分:0)

运行此命令

npm install -g react-native-cli

之后,只需将npm路径添加到环境变量

中的系统变量
C:\Users\YOUR USERNAME\AppData\Roaming\npm