使用 CocoaPods 安装的框架的构建设置中的空 Info.plist 路径

Posted

技术标签:

【中文标题】使用 CocoaPods 安装的框架的构建设置中的空 Info.plist 路径【英文标题】:Empty Info.plist paths in build settings with frameworks installed with CocoaPods 【发布时间】:2020-03-31 19:04:41 【问题描述】:

我的 CocoaPods 有问题,每次我尝试运行命令 pod install 时,pod 都已正确安装,但每个链接框架的构建设置中的 Info.plist 文件路径始终为空,这会在我运行时导致错误尝试安装并运行我的应用程序。

这是我的 Podfile,我正在使用 react-native:

platform :ios, '9.0'
use_frameworks!

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

def add_flipper_pods!
  version = '~> 0.33.1'
  pod 'FlipperKit', version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug'
  pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug'
end
# Post Install processing for Flipper
def flipper_post_install(installer)
  installer.pods_project.targets.each do |target|
    if target.name == 'YogaKit'
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '4.1'
      end
    end
  end
end


target 'myproject' do

  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-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  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/callinvoker', :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', :modular_headers => true

  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'

  pod 'FBSDKCoreKit', '5.7'
  pod 'FBSDKLoginKit', '5.7'
  pod 'FBSDKShareKit', '5.7'

  use_modular_headers!
  use_native_modules!

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  # add_flipper_pods!
  # post_install do |installer|
  #  flipper_post_install(installer)
  # end

end

我已经尝试清理 cocoapods 缓存,重新安装 pod,删除 Xcode 派生文件夹,但似乎没有任何解决办法。

Info.plist 文件位于Pods/Target Support Files/*myframework*/*myframework*-Info.plist

有没有办法创建自定义安装后规则以正确重新分配它们? 似乎 pod 更新损坏了它们。

谢谢

【问题讨论】:

【参考方案1】:

我找到了解决方案,我创建了这个安装后脚本并解决了这个问题:

def info_post_install(installer)
  installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
            config.build_settings['INFOPLIST_FILE'] = 'Target Support Files/'+target.name+'/'+target.name+'-Info.plist'
        end
    end

end

post_install do |installer|
  info_post_install(installer)
end

我已经发布了它以防其他人将来遇到这个问题。

【讨论】:

以上是关于使用 CocoaPods 安装的框架的构建设置中的空 Info.plist 路径的主要内容,如果未能解决你的问题,请参考以下文章

CocoaPods 不适用于框架目标

使用 CocoaPods 有啥好处?

如何使用弱链接的 CocoaPods 库构建 iOS 框架

使用 cocoapods 的子规范构建 ios 框架的问题

cocoapods - ld:找不到框架

我下载了一个使用 CocoaPods 的开源项目。我必须安装 CocoaPods 吗?