ios - 使用 Podfile 时,为什么 Xcode 将所有 Swift 库(多次)安装到我的设备上?

标签 ios swift xcode cocoapods

我刚刚向我的 iOS 项目添加了一个 Podfile,无论我为 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 设置什么(甚至 $(inherited)),它仍然会将所有这些 swift 库添加到我的构建中。在添加 Podfile 之前,我的应用程序大约有 20 MB,现在是 1.35 GB...我已经进行了大量的谷歌搜索,但我似乎无法弄清楚是什么原因造成的。我使用的是 Xcode 10.1,这是我的 Podfile:

platform :ios, '10.0'

target 'MyApp' do
  use_frameworks!

  # Core Dependencies
  pod 'SwiftLint', '~> 0.29.1'
  pod 'R.swift', '~> 5.0.0.rc.1'
  pod 'RxSwift', '~> 4.4.0'
  pod 'RxCocoa',    '~> 4.4.0'
  pod 'Alamofire', '~> 4.8.0'
  pod 'Moya/RxSwift', '~> 12.0.1'

  # Database management
  pod 'RxRealm', :git => 'https://github.com/RxSwiftCommunity/RxRealm', :tag => '0.7.7'
  pod 'RealmSwift', '~> 3.12.0'

  # Remote Image management
  # pod 'Kingfisher', '~> 4.6.3'

  target 'MyAppTests' do
    inherit! :search_paths
    pod 'Nimble', '~> 7.3.1'
    pod 'SnapshotTesting', '~> 1.0'
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    pod 'Nimble', '~> 7.3.1'
    pod 'SnapshotTesting', '~> 1.0'
  end

end
post_install do |installer_representation|
  installer_representation.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
    end
  end
end

最佳答案

好吧,经过几个小时的挫败感,我终于发现了导致问题的原因。事实证明我错过了一个重要的步骤:清理构建文件夹

每当您对 Podfile 进行更改时,都需要重新运行 pod install,然后单击“项目”菜单下的“清理构建文件夹”。

以下是 Podfile 底部的正确代码,可阻止安装 Swift 标准库的多个副本:

post_install do |installer_representation|
  installer_representation.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = '$(inherited)'
    end
  end
end

完成此操作后,我的应用程序恢复到原来的小尺寸。编码愉快!

关于ios - 使用 Podfile 时,为什么 Xcode 将所有 Swift 库(多次)安装到我的设备上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54640021/

相关文章:

ios - 使用 Storyboard 或 xib 文件开发应用程序

ios - WKWEBVIEW 仅显示网站的移动版本

ios - 如何获取 UITableView 中动态大小的节标题的高度?

ios - 如何找出底部安全区域边缘到屏幕底部的距离?

ios - XCode 7 和 iOS 8 自动布局顶部约束问题

ios - 未为 ChildViewController 更新父变量

iphone - iPhone 中的图像尺寸不正确

ios - 我怎样才能停止在 Swift 中执行一个 Action ?

ios - controllerDidChangeContent 内的 EXC_BAD_ACCESS : at line tableView. endUpdates()

ios - NSParameterAssert 可以留在生产代码中吗?