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

时间:2019-02-11 22:18:44

标签: ios swift xcode cocoapods

我刚刚将Podfile添加到了我的iOS项目中,无论我为ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES(甚至$(继承))设置了什么,它仍然会将所有这些快速库添加到我的构建中。在我添加Podfile之前,我的应用程序约为20 MB,现在为1.35 GB。我已经进行了大量的Google搜索,但我似乎无法弄清楚是什么原因引起的。我正在使用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

1 个答案:

答案 0 :(得分:0)

嗯,经过数小时的挫折,我终于发现了问题的根源。事实证明,我错过了一个重要步骤:清理构建文件夹

每当对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

完成此操作后,我的应用将恢复为原始的小尺寸。编码愉快!