I am trying to create a react-native project using react-native cli. Command I used to create project
- npx react-native init test
After this if I try to run this app by
- cd test & npx react-native run-android
But I get this error:
error Android project not found. Are you sure this is a React Native project? If your Android files are located in a non-standard location (e.g. not inside 'android' folder), consider setting project.android.sourceDir
option to point to a new location.
I have android, ios folder in root project and node version is 16.15.0
This is my project json:
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "17.0.2",
"react-native": "0.68.2"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.67.0",
"react-test-renderer": "17.0.2"
},
"jest": {
"preset": "react-native"
}
}
CodePudding user response:
I tried debugging the problem. I compared my old projects to the ones I'm creating now. If I try to type npx react-native config
on the new one this will show:
"project": {
"ios": {
"sourceDir": "C:\\Users\\robby\\testingproject\\ios",
"folder": "C:\\Users\\robby\\testingproject",
"pbxprojPath": "C:\\Users\\robby\\testingproject\\ios\\testingproject.xcodeproj\\project.pbxproj",
"podfile": "C:\\Users\\robby\\testingproject\\ios\\Podfile",
"podspecPath": null,
"projectPath": "C:\\Users\\robby\\testingproject\\ios\\testingproject.xcodeproj",
"projectName": "testingproject.xcodeproj",
"libraryFolder": "Libraries",
"sharedLibraries": [],
"plist": [],
"scriptPhases": []
},
"android": null
} }
In my older project:
"project": {
"ios": {
"sourceDir": "C:\\Users\\robby\\SwaPH\\ios",
"folder": "C:\\Users\\robby\\SwaPH",
"pbxprojPath": "C:\\Users\\robby\\SwaPH\\ios\\SwaPH.xcodeproj\\project.pbxproj",
"podfile": "C:\\Users\\robby\\SwaPH\\ios\\Podfile",
"podspecPath": null,
"projectPath": "C:\\Users\\robby\\SwaPH\\ios\\SwaPH.xcodeproj",
"projectName": "SwaPH.xcodeproj",
"libraryFolder": "Libraries",
"sharedLibraries": [],
"plist": [],
"scriptPhases": []
},
"android": {
"sourceDir": "C:\\Users\\robby\\SwaPH\\android",
"isFlat": true,
"folder": "C:\\Users\\robby\\SwaPH",
"stringsPath": "C:\\Users\\robby\\SwaPH\\android\\app\\src\\main\\res\\values\\strings.xml",
"manifestPath": "C:\\Users\\robby\\SwaPH\\android\\app\\src\\main\\AndroidManifest.xml",
"buildGradlePath": "C:\\Users\\robby\\SwaPH\\android\\build.gradle",
"settingsGradlePath": "C:\\Users\\robby\\SwaPH\\android\\settings.gradle",
"assetsPath": "C:\\Users\\robby\\SwaPH\\android\\app\\src\\main\\assets",
"mainFilePath": "C:\\Users\\robby\\SwaPH\\android\\app\\src\\main\\java\\com\\swaph\\MainApplication.java",
"packageName": "com.swaph",
"packageFolder": "com\\swaph",
"appName": "app"
}
}
As far as I know, the android represents the android folder in the root folder. Without the project detecting it, we are unable to run npx react-native run-android
or react-native run-android
. I still haven't found any fix that works yet.
CodePudding user response:
I have the same problem. hour ago my project worked fine. suddenly it's giving that error and none of the old solutions eject or upgrade are not solving it an
CodePudding user response:
I was facing the same issue too so i've created a thread on r/reactnative and someone kind provided a solution. Not sure why, but it works for me. The solution is:
- delete node_modules
- add this to package.json: "resolutions": { "glob": "7.2.0" }
- install node_modules with yarn or npm
https://www.reddit.com/r/reactnative/comments/uphynu/hello_there_is_a_new_error_i_guess/
CodePudding user response:
The issue comes after react 7.2.2 was released. Follow the following steps and recompile the project.
- Clear node_modules
- add this to package.json "resolutions": { "glob": "7.2.0" }
- Reinstall node_modules with npm install
If this not work try this command
" yarn add [email protected]"