gpt4 book ai didi

android - React-Native 更改 iOS 和 Android 文件夹的默认位置

转载 作者:行者123 更新时间:2023-12-03 11:17:02 24 4
gpt4 key购买 nike

根据react-native cli documentation我们可以根据每个平台为 RN cli 指定自定义配置。
我想更改每个平台文件夹的默认位置,所以我添加了我的自定义 react-native.config.js到项目的根目录,您可以在此处找到:

module.exports = {
project: {
ios: {
project: './example/ios/example.xcworkspace',
},
android: {
sourceDir: './example/android/',
},
},
};

如果我运行 react-native config在根文件夹中,我可以看到正确的配置:

{
...
"project": {
"ios": {
"sourceDir": "path-to-project-directory/example/ios",
"folder": "path-to-project-directory",
"pbxprojPath": "path-to-project-directory/example/ios/example.xcworkspace/project.pbxproj",
"podfile": "path-to-project-directory/example/ios/Podfile",
"podspecPath": null,
"projectPath": "path-to-project-directory/example/ios/example.xcworkspace",
"projectName": "example.xcworkspace",
"libraryFolder": "Libraries",
"sharedLibraries": [],
"plist": [],
"scriptPhases": []
},
"android": {
"sourceDir": "path-to-project-directory/example/android/",
"isFlat": true,
"folder": "path-to-project-directory",
"stringsPath": "path-to-project-directory/example/android/app/src/main/res/values/strings.xml",
"manifestPath": "path-to-project-directory/example/android/app/src/main/AndroidManifest.xml",
"buildGradlePath": "path-to-project-directory/example/android/build.gradle",
"settingsGradlePath": "path-to-project-directory/example/android/settings.gradle",
"assetsPath": "path-to-project-directory/example/android/app/src/main/assets",
"mainFilePath": "path-to-project-directory/example/android/app/src/main/java/com/example/MainApplication.java",
"packageName": "com.example",
"packageFolder": "com/example",
"appName": "app"
}
}
}

问题是每当我运行 react-native run-ios我收到此错误:

error iOS project folder not found. Are you sure this is a React Native project?. Run CLI with --verbose flag for more details.

注意:我正确安装了所有依赖项。这是 react-native --v 的结果命令:

react-native-cli: 2.0.1
react-native: 0.62.0

最佳答案

"react-native": "0.63.4"对于 iOS,您需要指定 --project-path prop 在你的运行脚本中,而不是在 react-native.config.js
您的运行脚本应如下所示:"ios": "react-native run-ios --project-path './<new folder>/ios'"但之后您需要将路径更新为 ../../node_modules/位于许多 native 文件中的模块,如 Podfile , ios/<your project name>.xcodeproj/project.pbxproj您可以查看更多here

关于android - React-Native 更改 iOS 和 Android 文件夹的默认位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60937667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com