React native: Android project not found. Maybe run react-native android first?

udai picture udai · May 1, 2017 · Viewed 66k times · Source

I had an issue in my React-Native project which was working fine earlier but suddenly it stopped working. Whenever I used the command:

react-native run-android

I was getting an error:

Android project not found. Maybe run react-native android first?

I tried running:

react-native android

But it said:

Unrecognized command 'android' Run react-native --help to see list of all available commands

After trying:

D:\ProjectRoot\ReactNativeProjects\AwesomeProject>react-native eject

The error returned was:

Scanning folders for symlinks in D:\ProjectRoot\ReactNativeProjects\AwesomeProject\node_modules (48ms) App name must be defined in the app.json config file to define the project name. It must not contain any spaces or dashes.

This is the app.json file:

{
  "expo": {
    "name": "AwesomeProject",
    "description": "A very interesting project.",
    "slug": "AwesomeProject",
    "privacy": "public",
    "sdkVersion": "30.0.0",
    "platforms": ["ios", "android"],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "package": "com.project.first"
    },
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/images/icon.png",
    "splash": {
      "image": "./assets/images/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ]
  }
}

Answer

udai picture udai · May 1, 2017

I raised this question and answered myself as I thought it will help others who are facing similar issue. I struggled a lot to find out the real reason behind it as the error shown in terminal was not precise.

To resolve the issue please upgrade the react-native package.

  1. Go to the Project root.

  2. Upgrade the React native package in the Command Prompt by typing :

    react-native upgrade.

  3. Then Accept to update all the Files by typing y (Yes) in the Command Prompt.

Reference: https://github.com/facebook/react-native/issues/9312