如何排除 SKAdvisorResources.bundle 在应用程序中被复制?

How can I exclude SKAdvisorResources.bundle from being copied within the app?

鉴于我不需要捆绑包 SKAdvisorResources,因为我不使用任何语音建议或导航,我怎样才能避免它最终出现在我的 ipa 中?

我已经将 SKMaps 添加到我的项目中作为 pod 依赖项,只需将 pod 'ScoutMaps-iOS-SDK' 添加到我的 Podfile 中即可。

我想出的解决方案是向我的项目添加一个自定义脚本阶段,该阶段在导出包之前将其删除;如果您想更新 pods,这是安全的,但我不太喜欢,我更愿意在我的 Podfile 中指定一些排除规则,但我不知道这是否可能...

rm -rf "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/SKAdvisorResources.bundle"
rm -rf "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/SKAdvisorResources.bundle"

我知道这是一个老问题,可能你有解决方案(或决定使用另一个库)

但以备日后参考

THIS WORKS ON MacOS for other systems you need to check your available tools find, sed

您可以在 Podfile

post_install do |installer|    
    app_target = "your_target_goes_here"
    puts("* Commenting file `Pods-#{app_target}-resources.sh` line having `SKAdvisorResources.bundle`")
    system("find . -name \"Pods-#{app_target}-resources.sh\" -exec sed -i '' -e \"/SKAdvisorResources.bundle/s/^/#/\" {} +")
end

让我们在这里添加一些解释以备不时之需并需要更新 xD

解释:

  • /SKAdvisorResources.bundle/ 匹配一行 SKAdvisorResources.bundle里面
  • s 对上面匹配的行执行替换
  • 如果匹配,则插入哈希字符 # 在行首 ^

根据@yeradis 的建议,我的最终解决方案循环遍历 podfile 中定义的目标聚合列表,并将替换应用于所有文件。

post_install do |installer|
    installer.aggregate_targets.each do |target|
        puts("* Commenting file `#{target.label}-resources.sh` lines having `SKAdvisorResources.bundle`")

        system("find . -name \"#{target.label}-resources.sh\" -exec sed -i '' -e \"/SKAdvisorResources.bundle/s/^/#/\" {} +")
    end
end

注意 target.label returns 一个包含 Pods- 前缀的字符串