ChatGPT解决这个技术问题 Extra ChatGPT

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

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": [
      "**/*"
    ]
  }
}
if android folder is missing in root directive then run react-native eject.
@Khurshid Ansari your solution did not work, as the error is coming: "App name must be defined in the app.json config file to define the project name" even when the name is defined. Please see the updated question.
Check your AndroidManifest.xml file. Usually, It comes when there is some error in the AndroidManifest.xml file.

C
Community

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.

Go to the Project root. Upgrade the React native package in the Command Prompt by typing : react-native upgrade. Then Accept to update all the Files by typing y (Yes) in the Command Prompt.

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


Saved the day :)
where is the React native package found? please make clear steps
@LutaayaHuzaifahIdris As mentioned in the answer, the react native package can be upgraded on Project root. So, open command prompt and go to the project root. Then upgrade the react native package.
it is upgraded react-native which i didn't want.
My working solution is below, none of the above worked for me:: 1. Open AVD manager in Android Studio and run a virtual device (you can close AS afterwards) 2. CMD into your project folder and type 'expo start' 3. Once Expo has started choose option 2 which is "Press a for Android emulator" It will install expo on the virtual device and you can test from there
S
Sahil Kalaigar

Open your React Native Project Root Directory and locate android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json . delete signing-config.json this file try again

Or

1)Sometimes if we have older version of react native and some of newly installed packages dose not support older version. Then you have to update the react native project using react-native upgrade command.

After done updating current project to new version this error should resolved.


This works for me, thanks.
If android\app\build\intermediates\signing_config\release\out\signing-config.json also deleted
J
José Abimael Martínez

I know it is an old question but any of those solutions did not work for me and maybe there are others like me. I solved my problem running this command before run-android

react-native eject

for some reason this did the trick for me too, I tried the newer version of react native upgrade using "react-native-git-upgrade" as suggested when you run "react-native upgrade" it didn't work for me.
this command re create android and ios folder in your project
I think this is the proper answer. Not only because it worked for me, but because from my understanding from the docs, this is the intended way to do it and therefore without other side-effects.
The eject command has been removed from react-native.
A
Abhinav Saxena

Make sure to start the project using command (non-expo):

react-native init <your-project-name>

If existing folder, then follow:

react-native eject

In the latest version of react-native this suggestion comes when you try to issue the command:

react-native eject

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.

Now when you issue the following command:

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

The following shows up:

Scanning folders for symlinks in D:\ProjectRoot\ReactNativeProjects\AwesomeProject\node_modules (56ms) You should consider using the new upgrade tool based on Git. It makes upgrades easier by resolving most conflicts automatically. To use it: - Go back to the old version of React Native - Run "npm install -g react-native-git-upgrade" - Run "react-native-git-upgrade" See https://facebook.github.io/react-native/docs/upgrading.html react-native version in "package.json" doesn't match the installed version in "node_modules". Try running "npm install" to fix this. Aborting.

In the Facebook react-native commands suggestions, there is a clear solution.

These commands check the current version and whether there is update needed or not.

One more solution:

react-native: Command run-android unrecognized. Maybe caused by npm install

Please also see:

Solution to "Expo : cannot find a module LogReporter"


Accepted answer for me, +10 rep. to @Abhinav
k
karthik mano

Open Command Prompt as Administrator and goto the project folder, run android(npx react-native run-android)


m
m9m9m

I did like this... Worked !!

In the CMD Project root run react-native upgrade. if you are still getting issues, make sure you have react-native in dependencies json in package.json, add it if not if you are still getting issues, get the version of react native in cmd using react-native -v and check if the value returned in cmd and package.json are same. update the package.json with the value returned in cmd

Here my problem solved.


s
sem10

Running Terminal as Administrator in Windows did the trick for me... Other solutions did not work.


This is only saying thanks to the existing answer by karthik mano, isn't it? If not please make more obvious what additional insight this answer provides.
B
Bobo Chen

I had to restyle my AndroidManifest.xml because I had a syntax error somewhere (I had an extra "/" somewhere). Now it's fixed. Be very careful with your syntax...


How is this an answer?
N
NewPHPer

Remove the file: React Native Project Root Directory and locate android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json .


Or just delete the entire build folder inside the app.
G
Guilherme Andrade

Open your React Native Project Root Directory and locate android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json

Delete the file and try again.


I
Ilya Zatolokin

We had this issue because files from android folder gradlew and gradlew.bat (Gradle startup script for the UN*X, Windows respectively) somehow got into the global .gitignore file, and so were not presented on local environments.

Actually running react-native upgrade command restore those files, thus fixing the problem.


F
Filipe

As a complement, in the case react-native command is not found, you should install react-native CLI:

npm install -g react-native-cli

Then you can follow the steps people said above.

More details: react-native: command not found


B
Ben Hur Martins

I faced this problem today, and none of the solutions worked for me, so I found another one.

Badly Formatted AndroidManifest.xml will cause this problem, perhaps you set the splash screen like me today, and didn't formatted AndroidManifest in the correct way


أ
أحمد رحماني

Delete signing-config.json next try again react-native run-android

signing-config.json file Path : android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json


A
Abhi

If you started your project by following

npm install -g create-react-native-app
create-react-native-app MyReactNative
npm install -g react-native-cli
npm start

after this, you can face problem mention above in question So the solution is :

npm run eject

M
Michimcchicken

I'm using Android Studio (non-expo) and this works for me

react-native init <your-project-name>

A
Ajeet Singh

I think one more simple thing you could have checked, is if previously you ran the project as different role of a user, like in windows if you ran previously the react-native run-android with an administrator role.


I had similar issue to the question above and starting the terminal with admin permissions (on Windows) this error went away.
C
Community

For me, "rm -rf android/app/build/" worked

Run your command with "--verbose". I got the error that it couldn't read a file (in android/app/build/generated/not_namespaced_r_class_sources/). I deleted this folder, and it worked


h
hp2017

Here, app.json does not have name, but it has expo related config. So just add name and display name fields in app.json.

app.json (first two lines) :

{
"name": "AwesomeProject",
"displayName": "Awesome Project",
"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": [
      "**/*"
    ]
  }
}

After this, just run :

$ react-native eject

info Generating the iOS folder.

info Generating the Android folder.

No need to do react-native upgrade.


actually, "expo eject" also works better. It gave me options and updated app.json and created android/ios directories.
h
hino

You have to run your cmd with admin priviliges. That solved the same issue for me. Didnt do "eject" or anything else.


There are lot of similar answers avaialble for the same question. Instead of adding your answer, you could just upvote the existing answer if it helped you.
P
Praneeth Pj

In my case, I've forgotten to add Sudo. Fixed as follows,

sudo npx react-native run-android

T
Thirasha

Delete react native android build folder and then retry command npx react-native run-android


Y
Yan Jardim

In my case i didn't had the right permissions for my project folder.

If this is your case just click with the right button on the folder > Properties > Security > Advanced and then change the ownership of the folder to your user, including the subfolders. That should do it


F
Faisal Mushtaq

This error simply means you don't have 'android' and 'ios' folders in your root directory of the project. Their location is important.

SOLUTION:-

Open your project folder search for 'android' and iso 'folder', move these folders in your root folder of the project and then start the project with react-native run-android

https://i.stack.imgur.com/fg8Cw.png


M
Melvin Chipimo

So if there is anyone having this issue here what worked for me,

{
   "name": "ZedMusic",
   "displayName": "zedmusic",
   "expo": {}
}

the project name must be outside expo, then run npx react-native eject


P
Paul Gwamanda

My working solution is below, none of the above worked for me:

CD into your project folder and type expo start --android.

Or the long way:

Open AVD manager in Android Studio and run a virtual device (you can close AS afterwards) CMD into your project folder and type 'expo start' Once Expo has started choose option 2 which is "Press a for Android emulator"

It will install expo on the virtual device and you can test from there


a
a_rahmanshah

When I ran react-native eject, I got this error:

Both the iOS and Android folders already exist! Please delete `ios` and/or `android` before ejecting.

Delete the MyProject/android folder.

Run react-native eject This generated the android folder

Then run react-native run-android to build android


s
stainlessbaby

You should consider using the new upgrade tool based on Git. It makes upgrades easier by resolving most conflicts automatically. To use it: - Go back to the old version of React Native - Run "npm install -g react-native-git-upgrade" - Run "react-native-git-upgrade" See https://facebook.github.io/react-native/docs/upgrading.html


M
Martijn Pieters

If you have created your project with the expo command, like expo init projectname, then afterwards you have to eject your project:

expo eject

If you have created you project by react-native init projectName then you have to use

react-native eject

The eject command has been removed from react-native github.com/react-native-community/cli/pull/275
D
Dinesh Kumar

May be it's too late, I replaced the Android folder from a backup file. It worked for me.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now