ios - 无法运行 ios 的 React Native 项目

标签 ios react-native cocoapods

我正在开发React Native应用程序,我是React-Native新手,首先我曾在Android平台上工作并成功构建了apk文件。 现在我想使用我的 macbook 中的命令 react-native run-ios 运行 ios 版本,但它会引发错误:

注意:从一开始我就在 MacBook 上开发了这个应用程序

user-MacBook-Pro:myApp user$ react-native run-ios
error Cannot read property 'podfile' of null. Run CLI with --verbose flag for more details.
TypeError: Cannot read property 'podfile' of null
    at warnAboutPodInstall (/Users/user/project/myApp/node_modules/@react-native-community/cli-platform-ios/build/link/warnAboutPodInstall.js:43:90)
    at Object.runIOS [as func] (Users/user/project/myApp/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js:80:36)
    at Command.handleAction (Users/user/project/myApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:164:23)
    at Command.listener (Users/user/project/myApp/node_modules/commander/index.js:315:8)
    at Command.emit (events.js:198:13)
    at Command.parseArgs (Users/user/project/myApp/node_modules/commander/index.js:651:12)
    at Command.parse (Users/user/project/myApp/node_modules/commander/index.js:474:21)
    at setupAndRun (Users/user/project/myApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:237:24)
    at Object.run (Users/user/project/myApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:184:11)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:117:7)

Pod文件

 platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

 target 'myApp' do
  # Pods for myApp
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  target 'myAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'myApp-tvOS' do
  # Pods for myApp-tvOS

  target 'myApp-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

请知道解决办法的人帮帮我。 提前致谢。

最佳答案

  1. 打开终端
  2. ios 文件夹移动到 React-Native 项目下
  3. 运行pod install命令 - 这将为已安装的需要链接的 rpm 模块安装所有链接库。
  4. 之后运行react-native run-ios双击projectName.xcworkspace,这将打开Xcode。
  5. 选择要运行和播放项目的设备。

关于ios - 无法运行 ios 的 React Native 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59926743/

相关文章:

ios - 如何解决 Cocoapods lint 命令中的链接器错误?

android - 如何设置 ScrollView 以适应 React Native?

ios - UITapGestureRecognizer 与 didSelectRowAtIndexPath 并发性

android - React Native:任务:app:installDebug失败

react-native - 用破折号 react 字符串的原生文本分词策略

ios - 使用 cocoapods 的 PayPal-iOS-SDK 在桥接头中抛出错误

ios - Cocoapods部署目标问题

ios - iTunesConnect 是否使用最近的翻译?

ios - 阻止在 TableView 的特定单元格中重新排序

android - 在 react-native 中打开 webview 时出现 ClassNotFoundException