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 theapp.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": [
"**/*"
]
}
}
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
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
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.
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 theapp.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.
Please also see:
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.
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
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
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 theandroid
folderThen run
react-native run-android
to build android
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
来源:https://stackoverflow.com/questions/43723958/react-native-android-project-not-found-maybe-run-react-native-android-first