简体   繁体   English

react-native run-android 无法识别

[英]react-native run-android is unrecognized

I've installed react-native-cli globally:我已经在全球范围内安装了 react-native-cli:

npm install -g react-native-cli

Then run:然后运行:

react-native init AwesomeProject
cd AwesomeProject

I got the following structure:我得到以下结构:

-- AwesomeProject   
---- node_modules      
------ react-native    

When I run react-native run-android I get an error:当我运行react-native run-android时出现错误:
Command run-android unrecognized.命令run-android无法识别。 Did you mean to run this inside a react-native project?您的意思是在 react-native 项目中运行它吗?

When I run react-native start I get the same.当我运行 react-native start 时,我得到了同样的结果。

react-native -v
prints:印刷:
react-native-cli: 0.2.0反应原生 cli:0.2.0
react-native: n/a - not inside a React Native project directory react-native:n/a - 不在 React Native 项目目录中

What I'm doing wrong?我做错了什么?

What caused this for me was running npm install --save [package] when actually the system has previously been using yarn instead of npm .对我造成这种情况的原因是运行npm install --save [package]而实际上系统以前一直在使用yarn而不是npm

To solve this I just deleted the node_modules folder and ran: yarn install and after that react-native run-ios (or android) works fine.为了解决这个问题,我刚刚删除了node_modules文件夹并运行: yarn install然后react-native run-ios (或 android)工作正常。

(duplcate of React Native: Command `run-ios` unrecognized ) React Native 的副本:命令 `run-ios` unrecognized

我只是在没有参数的情况下运行“纱线”并修复了它。

Please try this cmd it will be help you请试试这个cmd它会帮助你

npm install --save react-native

Yes Thanks For Share This Its Work For me Thanks For Helping Good是的,谢谢分享,这对我有用,谢谢你的帮助

the answer is easy nad it is not because of any bug at all.答案很简单,这根本不是因为任何错误。

make sure you are in correct directory 

if in current directory there is not any react native app ,it gives you this error如果在当前目录中没有任何反应本机应用程序,它会给你这个错误

The problem was that I terminated init command because it looked like hanged without errors (even 24 hours later).问题是我终止了init命令,因为它看起来没有错误(即使是 24 小时后)。 To fix this I updated nodejs and npm to newer versions.为了解决这个问题,我将 nodejs 和 npm 更新到了较新的版本。 Once I have done it react-native init was executed properly and there is no more problem with react-native run-android .一旦我完成它, react-native init 就会正确执行,并且react-native run-android不再有问题。

you have to update your npm.你必须更新你的 npm。 To do that这样做

npm install npm@latest -g

react-native run-android is unrecognized react-native run-android 无法识别

Make sure that you have installed npm or use in your project directory确保您已安装 npm 或在您的项目目录中使用

npm install

try "yarn install".尝试“纱线安装”。 It will install the missing files in node_modules它将在 node_modules 中安装丢失的文件

It worked for me它对我有用

This can be caused by a couple of issues.这可能是由几个问题引起的。

!!! !!! Before trying each solution remember to open a new terminal since you might have old paths sources from your .bashrc file.在尝试每个解决方案之前,请记住打开一个新终端,因为您可能有来自 .bashrc 文件的旧路径源。 !!! !!!

  1. You did not install the contents of the project .您没有安装项目的内容 In order to solve this you have to install the node_modules by typing:为了解决这个问题,您必须通过键入以下内容来安装 node_modules:

    npm install or yarn install

  2. You are coming back to a previously installed project after doing some funny things with your react-native installation and global configurations .在使用 react-native 安装和全局配置做了一些有趣的事情后,您将回到以前安装的项目 (Upgrading the library, upgrading node doing something with globally installed node_modules). (升级库,升级节点,使用全局安装的 node_modules 做一些事情)。

You should clean all your caches and project modules您应该清理所有缓存和项目模块

Here you can find a command to do all these things in one line (remember to replace npm with yarn accordingly): https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d在这里你可以找到一个命令来在一行中完成所有这些事情(记得相应地用 yarn 替换 npm): https : //gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d

  1. Your global installation of react-native or react-native-cli is broken .您的 react-native 或 react-native-cli 的全局安装已损坏 In this case simply reinstall your libraries globally.在这种情况下,只需全局重新安装您的库。

    npm: npm install -g react-native && npm install -g @react-native-community/cli npm: npm install -g react-native && npm install -g @react-native-community/cli

    yarn: yarn global add react-native && yarn global add @react-native-community/cli yarn: yarn global add react-native && yarn global add @react-native-community/cli

I think the command you are looking for is react-native run-android.我认为您正在寻找的命令是 react-native run-android。

cd into your project and run this command where all you js files are present and not in the android folder. cd 进入您的项目并运行此命令,其中所有 js 文件都存在,而不是在 android 文件夹中。

It will run a package manager, do not close that.它将运行一个包管理器,不要关闭它。 Also you need to have an emulator or a device connected to your computer with usb debugging enabled.此外,您还需要在启用 USB 调试的情况下将模拟器或设备连接到您的计算机。

Hope the answer helped希望回答有帮助

npx react-native run-android

使用 npx 将选择本地 npm node_modules 目录

执行npm install然后运行react-native run-android

  • Make sure you go into the directory having package.json确保进入包含 package.json 的目录

  • If you have deleted nodemodules try "npm install".如果您删除了节点模块,请尝试“npm install”。

  • And don't forget the "init" in "react-native init MyApp".并且不要忘记“react-native init MyApp”中的“init”。 "init" “初始化”
    initializes the package.json.初始化 package.json。

You can solve this by yarn or npx:你可以通过 yarn 或 npx 来解决这个问题:

yarn react-native run-android
npx react-native run-android

I did everything correct while setting up, but was unable to run the android code.我在设置时做的一切都正确,但无法运行 android 代码。 Just make sure while running the command react-native run-android that, you are inside the AwesomeProject folder created by the react-native init AwesomeProject command.只需确保在运行命令react-native run-android ,您位于react-native init AwesomeProject命令创建的 AwesomeProject 文件夹中。

The folder by default for my PC was under C:\\Windows\\system32\\AwesomeProject in Windows.默认情况下,我的 PC 的文件夹位于 Windows 中的C:\\Windows\\system32\\AwesomeProject

Hope it helped for the first timers :)希望它对初学者有所帮助:)

You need to update the project with the latest version of react-native.您需要使用最新版本的 react-native 更新项目。 Just run this command.只需运行此命令。

npm install --save react-native@latest

If you guys have latest react native version and facing this error如果你们有最新的本机版本并面临这个错误

"UNRECOGNIZED COMMAND run-android". “无法识别的命令运行 android”。

then run follow these steps it will definitely help you.然后按照这些步骤运行它肯定会帮助你。

Step: 1 -> create a new file " react-native.config.js " in the project root directory.步骤: 1 -> 在项目根目录新建一个文件“ react-native.config.js ”。

Step : 2 -> Inside " package.json " you have " assets " array inside " rnpm " object cut these assets from this and paste in your "react- native.config.js ".步骤:2 -> 在“ package.json ”中,“ rnpm ”对象中有“ assets ”数组, rnpm剪切这些资产并粘贴到“ react- native.config.js ”中。 ie:即:

module.exports = {
assets: ['./assets/fonts'],
}

Step : 3 -> Remove " rnpm " object from " package.json ".步骤:3 -> 从“ package.json ”中删除“ rnpm ”对象。

Step : 4 -> Replace your "scripts" with below mentioned "scripts" inside " package.json "步骤:4 -> 用下面提到的“ package.json ”中的“脚本”替换你的“脚本”

"scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "android:prod": "npx react-native run-android --variant=release",
    "ios:prod": "react-native run-ios --configuration Release"
  }

That's it Happy Hacking..............这就是快乐黑客......

Step 01 : Make sure that you are in right directory步骤 01:确保您在正确的目录中
Step 02 : npm install run this command步骤 02: npm install运行此命令
Step 03 : npm audit fix run this to fix issues步骤 03: npm audit fix运行这个来修复问题

Try deleting node_modules folder and then run the commands again尝试删除node_modules文件夹,然后再次运行命令

Everything has already tried like me?一切都已经像我一样尝试了吗? Then try again once "Yarn install after deleting node_modules".然后再试一次“删除 node_modules 后安装纱线”。 It worked for me.它对我有用。

Uninstall react-native from global从全局卸载react-native

$ npm uninstall -g react-native

Then然后

Install react-native to global安装react-native到全局

$ npm install -g react-native-cli

That worked for me那对我有用

react-native run-android


 start [options]                    starts the webserver
run-ios [options]                  builds your app and starts it on iOS simulator
run-android [options]              builds your app and starts it on a connected Android emulator or device
new-library [options]              generates a native library bridge
bundle [options]                   builds the javascript bundle for offline use
unbundle [options]                 builds javascript as "unbundle" for offline use
eject [options]                    Re-create the iOS and Android folders and native code
link [options] [packageName]       links all native dependencies (updates native build files)
unlink [options] <packageName>     unlink native dependency
install [options] <packageName>    install and link native dependencies
uninstall [options] <packageName>  uninstall and unlink native dependencies
upgrade [options]                  upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
log-android [options]              starts adb logcat
log-ios [options]                  starts iOS device syslog tail
dependencies [options]             lists dependencies
info [options]                     Get relevant version info about OS, toolchain and libraries

They have made some unnoticeable changes.他们做了一些不明显的变化。 For instance run-android(now) run android(before).例如 run-android(now) run android(before)。

尝试删除“package-lock.json”并重新运行“npm install”,然后尝试您的命令,它应该可以工作

I got this error because I had parenthesis in the path "(" and ")".我收到此错误是因为我在路径“(”和“)”中有括号。 Possibly this error is thrown for other special characters as well.其他特殊字符也可能引发此错误。

Ensure you run the command in the projects' terminal, preferably the Android IDE.确保在项目的终端(最好是 Android IDE)中运行该命令。 Run the adb devices to know your active devices as well运行adb devices以了解您的活动设备

If your package.json file is containing any comment then this error is comes.如果您的package.json文件包含任何注释,则会出现此错误。 So remove all comments from package.json and then run command it will work.因此,从package.json删除所有注释,然后运行命令它将起作用。

Also try to run command npm install --save then it will log if other error there.也尝试运行命令npm install --save然后它会记录是否有其他错误。 If any others error also there, then first fix it and then run command it will work.如果那里还有其他任何错误,请先修复它,然后运行命令它会起作用。

In Android Studio click in Tools -> SDK Manager -> in System Settings click in Android SDK -> choose tab SDK Tools, then enable Android SDK command line tools (lasted).在 Android Studio 中点击 Tools -> SDK Manager -> 在 System Settings 点击 Android SDK -> 选择标签 SDK Tools,然后启用 Android SDK 命令行工具(持续)。 It work for me!它对我有用!

Open your React Native Project Root Directory and locate android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json打开你的 React Native 项目根目录并找到android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json

Delete signing-config.json file删除signing-config.json文件

And rebuild your application.并重建您的应用程序。

react-native run-android

首先,您需要删除 node_mouldes 和 package.lock.json 并在此之后进行 yarn install 如果您使用的是 Windows 操作系统,则您需要使用 PowerShell 而不是 git bash 并编写此命令“react-native run-android”

再次安装 npm 到最新的 react-native init project_name cd project_name 打开 android studio 在你的 project_name react_native run_android 中打开同一个 android 文件夹现在就可以工作了

Found the solution below.在下面找到了解决方案。 npm install clear the react-native in node_modules npm install 清除 node_modules 中的 react-native

At first running npm install didn't work, but then, deleting the package-lock.json file and running npm install did the job.起初运行 npm install 没有用,但后来,删除 package-lock.json 文件并运行 npm install 完成了这项工作。

After that I installed react-navigation package seperately and it worked fine.之后我单独安装了 react-navigation 包,它运行良好。

I've installed react-native-cli globally:我已经在全球范围内安装了react-native-cli:

npm install -g react-native-cli

Then run:然后运行:

react-native init AwesomeProject
cd AwesomeProject

I got the following structure:我得到以下结构:

-- AwesomeProject   
---- node_modules      
------ react-native    

When I run react-native run-android I get an error:当我运行react-native run-android时出现错误:
Command run-android unrecognized.无法识别run-android命令。 Did you mean to run this inside a react-native project?您的意思是要在本机项目中运行它吗?

When I run react-native start I get the same.当我运行react-native启动时,我会得到相同的结果。

react-native -v
prints:印刷:
react-native-cli: 0.2.0 react-native-cli:0.2.0
react-native: n/a - not inside a React Native project directory react-native:不适用-不在React Native项目目录中

What I'm doing wrong?我做错了什么?

上次您的项目运行良好,现在您突然收到此错误并且您已经安装了 Node 模块,然后尝试npm install --save react-native为我工作

In my case, I forgot to run npm install before running react-native run-android .就我而言,我忘记在运行react-native run-android之前运行npm install I know this is a silly mistake but it may help.我知道这是一个愚蠢的错误,但它可能会有所帮助。

In my case, there was an extra comma in the Package.json in the "dependencies" section.就我而言,“依赖项”部分的 Package.json 中有一个额外的逗号。 "use-is-mounted-ref": "^1.4.0", "use-is-mounted-ref": "^1.4.0",

This made react to not be able to update, install anything.这使反应无​​法更新,安装任何东西。 Last line shouldn't have any comma最后一行不应有任何逗号

First, ensure you have configured environment variables correctly.首先,确保您已正确配置环境变量。 If yes, then make sure Powershell/cmd runs in the project's directory and node js is configured correctly.如果是,请确保 Powershell/cmd 在项目目录中运行并且 node js 配置正确。

I got this because I accidentally installed a react template and not a react-native template我得到这个是因为我不小心安装了一个反应模板而不是 react-native 模板

I've installed react-native-cli globally:我已经在全球范围内安装了react-native-cli:

npm install -g react-native-cli

Then run:然后运行:

react-native init AwesomeProject
cd AwesomeProject

I got the following structure:我得到以下结构:

-- AwesomeProject   
---- node_modules      
------ react-native    

When I run react-native run-android I get an error:当我运行react-native run-android时出现错误:
Command run-android unrecognized.无法识别run-android命令。 Did you mean to run this inside a react-native project?您的意思是要在本机项目中运行它吗?

When I run react-native start I get the same.当我运行react-native启动时,我会得到相同的结果。

react-native -v
prints:印刷:
react-native-cli: 0.2.0 react-native-cli:0.2.0
react-native: n/a - not inside a React Native project directory react-native:不适用-不在React Native项目目录中

What I'm doing wrong?我做错了什么?

I've installed react-native-cli globally:我已经在全球范围内安装了react-native-cli:

npm install -g react-native-cli

Then run:然后运行:

react-native init AwesomeProject
cd AwesomeProject

I got the following structure:我得到以下结构:

-- AwesomeProject   
---- node_modules      
------ react-native    

When I run react-native run-android I get an error:当我运行react-native run-android时出现错误:
Command run-android unrecognized.无法识别run-android命令。 Did you mean to run this inside a react-native project?您的意思是要在本机项目中运行它吗?

When I run react-native start I get the same.当我运行react-native启动时,我会得到相同的结果。

react-native -v
prints:印刷:
react-native-cli: 0.2.0 react-native-cli:0.2.0
react-native: n/a - not inside a React Native project directory react-native:不适用-不在React Native项目目录中

What I'm doing wrong?我做错了什么?

I forgot to change the directory first after run react-native init command.我在运行 react-native init 命令后忘记先更改目录。 When I ran command inside the react-native project directory it worked post that run the command npx react-native run-ios or run-andoid, it will work.当我在 react-native 项目目录中运行命令时,它会在运行命令 npx react-native run-ios 或 run-andoid 后运行,它将起作用。

error Unrecognized command "run-android". info Run "react-native --help" to see a list of all available commands.

Firstly you have run cmd line as a admin before enter "npx react-native init <your_project_name>" command.首先,在输入“npx react-native init <your_project_name>”命令之前,您已以管理员身份运行 cmd 行。 Then try other solutions.然后尝试其他解决方案。

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

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