初始 react-native run-ios 时缺少 Podfile.lock
Posted
技术标签:
【中文标题】初始 react-native run-ios 时缺少 Podfile.lock【英文标题】:Podfile.lock missing when initial react-native run-ios 【发布时间】:2019-10-24 17:45:06 【问题描述】:我正在为具有工作 android 版本的 React Native (0.61) 应用程序设置 ios 开发。我所做的是在通过在线帖子设置反应原生环境后复制组件的 src 和 package.json 文件(安装了 xcode 命令行工具 10.2)。但启动 run-ios 失败:
$ react-native run-ios
error Could not find "Podfile.lock" at /Users/mine/Documents/code/js/emps_fe6/ios/Podfile.lock. Did you run "pod install" in iOS directory?
error Could not find the following native modules: RNCAsyncStorage, RNDeviceInfo, RNGestureHandler, RNKeychain, BVLinearGradient, RNLocalize, RNReanimated, RNVectorIcons, react-native-video. Did you forget to run "pod install" ?
info Found Xcode project "emps_fe6.xcodeproj"
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
error Could not parse the simulator list output. Run CLI with --verbose flag for more details.
Error: Command failed: xcrun simctl list --json devices
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
at checkExecSyncError (child_process.js:629:11)
at Object.execFileSync (child_process.js:647:13)
at runOnSimulator (/Usersamine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js:130:54)
at Object.runIOS [as func] (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js:100:12)
at Command.handleAction (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli/build/index.js:164:23)
at Command.listener (/Users/mine/Documents/code/js/emps_fe6/node_modules/commander/index.js:315:8)
at Command.emit (events.js:198:13)
at Command.parseArgs (/Users/amine/Documents/code/js/emps_fe6/node_modules/commander/index.js:651:12)
at Command.parse (/Users/mine/Documents/code/js/emps_fe6/node_modules/commander/index.js:474:21)
at setupAndRun (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli/build/index.js:237:24)
这是 react native info 的输出:
$ react-native info
info Fetching system and libraries information...
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-2675QM CPU @ 2.20GHz
Memory: 194.93 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.17.0 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
IDEs:
Xcode: /undefined - /usr/bin/xcodebuild
npmPackages:
react: 16.11.0 => 16.11.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1
这是 package.json:
"dependencies":
"@react-native-community/async-storage": "^1.6.2",
"moment": "^2.24.0",
"react": "16.11.0",
"react-native": "0.61.2",
"react-native-cli": "^2.0.1",
"react-native-confirmation-code-field": "^4.1.0",
"react-native-device-info": "^4.0.1",
"react-native-elements": "^1.2.6",
"react-native-gesture-handler": "^1.4.1",
"react-native-gifted-chat": "^0.11.3",
"react-native-keychain": "^4.0.1",
"react-native-linear-gradient": "^2.5.6",
"react-native-localize": "^1.3.1",
"react-native-modal": "^11.4.0",
"react-native-modal-datetime-picker": "^7.6.0",
"react-native-reanimated": "^1.3.0",
"react-native-segmented-control-tab": "^3.4.1",
"react-native-vector-icons": "^6.6.0",
"react-native-video": "^5.0.2",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.10.2",
"react-navigation-tabs": "^2.5.6",
"simctl": "^2.0.0",
"socket.io-client": "2.1.1",
"xcode": "^2.0.0"
,
在错误消息中,提到了很多缺少的模块。但是这些模块已经安装,如 package.json 中所示。我不确定错误消息的含义。我也安装了simctl
但scrum simctl
仍然找不到它。我正在使用 VS Code 作为 IDE。
更新:
在/ios下创建了一个空的Podfile.lock
,运行-ios时变成了错误:
error Cannot read property 'SPEC CHECKSUMS' of undefined. Run CLI with --verbose flag for more details.
TypeError: Cannot read property 'SPEC CHECKSUMS' of undefined
at getDependenciesFromPodfileLock (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli-platform-ios/build/link-pods/getDependenciesFromPodfileLock.js:63:58)
at warnAboutPodInstall (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli-platform-ios/build/link/warnAboutPodInstall.js:43:67)
at Object.runIOS [as func] (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js:80:36)
at Command.handleAction (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli/build/index.js:164:23)
at Command.listener (/Users/mine/Documents/code/js/emps_fe6/node_modules/commander/index.js:315:8)
at Command.emit (events.js:198:13)
at Command.parseArgs (/Users/mine/Documents/code/js/emps_fe6/node_modules/commander/index.js:651:12)
at Command.parse (/Users/mine/Documents/code/js/emps_fe6/node_modules/commander/index.js:474:21)
at setupAndRun (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli/build/index.js:237:24)
at Object.run (/Users/mine/Documents/code/js/emps_fe6/node_modules/@react-native-community/cli/build/index.js:184:11)
【问题讨论】:
为什么不pod install
pod install
不起作用。
【参考方案1】:
首先安装 cocoapods
sudo gem install cocoapods
然后在根文件夹上运行以下命令
cd ios && pod install && cd ../ && react-native run-ios
【讨论】:
gem install cocoa pods
很好。但是/ios
下的pod install
有错误。 Command
config` 无法识别。确保您已运行 npm install
并且您位于 react-native 项目中。`该错误有点令人困惑。 [!] Podfile
文件无效:JSON 文本必须至少包含两个八位字节!`
我删除了 cocoa pods gem 并重新安装了它。还跑了npm install
。错误是一样的。
你能用yarn代替npm吗
我通常使用yarn install。问题是一样的。【参考方案2】:
第 1 步:
sudo gem install cocoapods
第 2 步:
cd ios && pod install && cd ../ && react-native run-ios
如果您在安装 pod 时仍然遇到错误,请继续执行以下步骤。
第 3 步:将其放入控制台 ->
xcrun -k --sdk iphoneos --show-sdk-path
如果答案是
xcrun:_ error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: unable to lookup item 'Path' in SDK 'iphoneos'
然后把这个:
sudo xcode-select --switch /Applications/Xcode.app
然后再次安装 pod
【讨论】:
命令“sudo xcode-select --switch /Applications/Xcode.app”给我错误:invalid developer directory '/Applications/Xcode.app' @EdwardRamos 我也是。 @Samim Hakimi,谢谢,它是为我运行的【参考方案3】:我遇到了同样的问题,我用下面的方法解决了这个问题。
导航到 iOS 文件夹,然后运行以下命令:
pod 更新
pod update 命令会更新所有依赖并生成一个"Podfile.lock" 文件。
【讨论】:
【参考方案4】:我有一个类似的问题,并通过跳转到 ios 文件夹并运行来解决它:
吊舱更新
直接在 ios 文件夹中执行此操作会生成 Podsfile.lock
从 ios 切换到主目录,然后我可以在 IOS 模拟器上使用以下命令启动应用程序:
npx react-native run-ios
【讨论】:
【参考方案5】:我尝试了很多解决方案。但最后尝试了一些合乎逻辑的东西。我不知道为什么我没有先尝试:)
pod install
不起作用。它没有任何改变。问题是“Podfile”在那里但不是“Podfile.lock”。那就是问题所在。当我们再次尝试安装时,它什么也没做,因为 Podfile 在那里。
解决方案是删除“Podfile”,然后再次删除 pod install
。然后你会看到两个文件“Podfile”和“Podfile.lock”。经过几个小时的挣扎,这就是我的解决方案,我尝试了很多事情:)祝大家好运。
【讨论】:
在之前的答案中已经推荐了使用详细命令进行安装和更新 是的,这是推荐的,但没有奏效:) 我的做法有一个不同。我先删除 podfile 后执行该安装命令。就我而言,如果 podfile 存在,则安装功能不会更改。我的问题是继续。当我从 ios 文件夹中删除 podfile 并使用 install 命令时,它工作得很好【参考方案6】:当您尝试开始一个项目时,此解决方案会起作用,我不知道它是否会在您遇到此问题时有所帮助。
这是我所做的:
安装 node.js(除非你已经下载)
检查:进入终端并输入:node -v安装 homeBrew(除非您已经下载)
要下载:进入终端并输入:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 记得阅读终端上的内容以完全下载它(应该像您输入的其他两个命令一样)安装守望者,在终端类型:brew install watchman
在终端上卸载你所有的 cocoapod 东西。检查如何使用此链接:https://superuser.com/questions/686317/how-to-fully-uninstall-the-cocoapods-from-the-mac-machine
打开 VScode
键入 npx react-native init TestProject
选择通过 Homebrew 安装 Cocoapods 的方法
这对我有用。
【讨论】:
以上是关于初始 react-native run-ios 时缺少 Podfile.lock的主要内容,如果未能解决你的问题,请参考以下文章
更新 xcode 13 后 react-native run-ios 命令未成功运行
`react-native run-ios` 返回错误:找不到 iPhone X 模拟器
react-native 0.57 run-ios 失败解决办法