react-native android 找不到项目错误
react-native android project not found error
我正在尝试使用 react-native cli 创建一个 react-native 项目。我用来创建项目的命令
- npx react-native 初始化测试
在此之后,如果我尝试 运行 这个应用
- cd 测试 & npx react-native 运行-android
但是我得到这个错误:
错误 Android 找不到项目。你确定这是一个 React Native 项目吗?如果您的 Android 文件位于非标准位置(例如不在 'android' 文件夹内),请考虑设置 project.android.sourceDir
选项以指向新位置。
我在根项目中有 android、ios 文件夹,节点版本是 16.15.0
这是我的项目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"
}
}
问题出现在glob@7.2.2 发布之后。按照以下步骤重新编译项目。
- 清除node_modules
- 将此添加到 package.json
“决议”:{“glob”:“7.2.0”}
- 使用 npm install
重新安装 node_modules
如果这不起作用,请尝试此命令
" 纱线添加 glob@7.2.0"
我试过调试问题。我将我的旧项目与我现在正在创建的项目进行了比较。如果我尝试在新的上输入 npx react-native config
,这将显示:
"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
}
}
在我的旧项目中:
"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"
}
}
据我所知,android代表根文件夹中的android文件夹。没有项目检测到它,我们无法 运行 npx react-native run-android
或 react-native run-android
。我还没有找到任何有效的修复方法。
我也遇到了同样的问题,所以我在 r/reactnative 上创建了一个讨论帖,有人提供了解决方案。不知道为什么,但它对我有用。
解决方案是:
- 删除node_modules
- 将此添加到 package.json: "resolutions": { "glob": "7.2.0" }
- 使用 yarn 或 npm 安装 node_modules
https://www.reddit.com/r/reactnative/comments/uphynu/hello_there_is_a_new_error_i_guess/
我正在尝试使用 react-native cli 创建一个 react-native 项目。我用来创建项目的命令
- npx react-native 初始化测试
在此之后,如果我尝试 运行 这个应用
- cd 测试 & npx react-native 运行-android
但是我得到这个错误:
错误 Android 找不到项目。你确定这是一个 React Native 项目吗?如果您的 Android 文件位于非标准位置(例如不在 'android' 文件夹内),请考虑设置 project.android.sourceDir
选项以指向新位置。
我在根项目中有 android、ios 文件夹,节点版本是 16.15.0
这是我的项目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"
}
}
问题出现在glob@7.2.2 发布之后。按照以下步骤重新编译项目。
- 清除node_modules
- 将此添加到 package.json “决议”:{“glob”:“7.2.0”}
- 使用 npm install 重新安装 node_modules
如果这不起作用,请尝试此命令
" 纱线添加 glob@7.2.0"
我试过调试问题。我将我的旧项目与我现在正在创建的项目进行了比较。如果我尝试在新的上输入 npx react-native config
,这将显示:
"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
} }
在我的旧项目中:
"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"
}
}
据我所知,android代表根文件夹中的android文件夹。没有项目检测到它,我们无法 运行 npx react-native run-android
或 react-native run-android
。我还没有找到任何有效的修复方法。
我也遇到了同样的问题,所以我在 r/reactnative 上创建了一个讨论帖,有人提供了解决方案。不知道为什么,但它对我有用。 解决方案是:
- 删除node_modules
- 将此添加到 package.json: "resolutions": { "glob": "7.2.0" }
- 使用 yarn 或 npm 安装 node_modules
https://www.reddit.com/r/reactnative/comments/uphynu/hello_there_is_a_new_error_i_guess/