You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native执行react-native android命令报错的解决求助

How to Run Your Expo React Native Project on Android Emulator/Device

Hey there! Let's break down why you're hitting that "Unrecognized command 'android'" error and get your app up and running smoothly.

The Core Issue

Your project is an Expo Managed React Native Project—you can spot this right away from your package.json:

  • The main entry points to node_modules/expo/AppEntry.js
  • All your scripts rely on expo start commands

The react-native android command only works for bare React Native projects (ones with a dedicated android directory). Since your project is managed by Expo, that command doesn't exist in this context—hence the error you're seeing.

Solutions to Launch Your App on Android

Your package.json already has a ready-to-use script for this! Just run one of these in your project root:

npm run android
# OR
yarn android

This command will:

  • Fire up the Expo development server
  • Automatically launch your Android emulator (if it's set up and ready)
  • Connect to a physical Android device (if you've enabled USB debugging and connected it to your computer)

2. Eject to a Bare React Native Project (Only If You Need Native Control)

If you need to modify native Android code (like adding custom native modules), you can eject your Expo project to a bare setup. Important: This is irreversible!

Run this command to start the eject process:

npm run eject
# OR
yarn eject

After ejecting, you'll see a new android directory in your project. From there, you can use the standard react-native run-android command to build and run the app.

Why Your Previous Fixes Didn't Work

Let's quickly clarify why those attempts didn't help:

  • react-native upgrade: This tool is for bare projects only; Expo handles upgrades through its own ecosystem.
  • yarn add react-native-cli: Expo projects don't need the standalone React Native CLI—Expo provides all the necessary commands out of the box.
  • yarn add android: There's no npm package named "android"; this command was never going to work.
  • npm run run:android: This script expects a gradlew file in an android directory, which your Expo project doesn't have yet.

Quick Pre-Checks to Ensure Success

Before running the commands, double-check these:

  • You have Android Studio installed with a working emulator (or a physical Android device connected via USB with debugging enabled)
  • You can see your device/emulator listed when running adb devices in your terminal

内容的提问来源于stack exchange,提问作者Yohanes AI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:26:19