Images.xcassets打破了目标定律 [英] Images.xcassets breaking the laws of targets

查看:137
本文介绍了Images.xcassets打破了目标定律的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我要为此努力,我衷心希望自己犯了一个愚蠢的错误(涉及到一些深夜).

Ok so i'm pulling my teeth out over this one and I sincerely hope i've made a stupid mistake (there have been some late nights involved).

简而言之,我们正在构建一种需要具有品牌效应的产品,因为多个客户将共享90%的相同UI和代码,并带有一些配置选项来打开/关闭事物以及不同的颜色,字体和图像等.

Short back story, we are building a product that needs to be brand-able as multiple customers will share 90% the same UI and code, with some config options to turn things on / off and different colours, fonts and images etc.

除.xcassets文件夹外,其他所有功能都可以正常工作.我每个客户有1个,目前他们拥有相同的资产名称,但具有不同的图像.例如,每个.xcassets都有一个ic_settings,但是每个内容都不同.

All working fine except the .xcassets folders. I have 1 per customer, currently they have the same asset names, with different images. For example, each .xcassets has a ic_settings, but the contents are different for each.

我已经检查了副本分发包资源的构建阶段,并且对于每个目标,实际上每个副本都只有一个.xcasset文件夹.

I've checked the copy bundle resources build phase and for each target, it does in fact only have 1 of the .xcasset folders for each.

<redacted image>

<redacted image>

当我运行应用程序时,它会正确加载appIcon(我必须将其重命名为appIcon- <target>,因为Xcode中的下拉列表显示了所有内容,而无法知道是哪一个).它还会显示正确的捆绑软件名称和启动screen.xib.

When I run the app, it correctly loads the appIcon (which I had to rename to appIcon-<target>, because the drop down in Xcode was showing them all and had no way to know which was which). It also displays the correct bundle name and launch screen.xib.

下面是图像本身.如您所见,图像是完全不同的:

Below are the images themselves. As you can see the images are quite different:

<redacted image> <redacted image>

但是当我运行客户1和客户2时,所有图像都是客户1的.

But When I run customer 1 and customer 2. All the images are customer 1's.

我不知道这是怎么可能的,请告诉我:

I don't know how this is physically possible, please tell me:

  1. 我不是疯了
  2. 我犯了一个我看不见的简单错误
  3. 这不是Xcode的错误,不需要进行过有关人类的最详尽的工作.可能重命名所有图像以附加目标名称:-(.

注意

我尝试在模拟器和真实设备上清理,构建,重置模拟器,删除派生数据等.

I have tried cleaning, building, reseting simulator, deleting derived data etc. Both on simulator and real device.

如果我将唯一的图像添加到其中一个文件夹,则可以使用它.难道感觉是Xcode正在合并文件夹吗???

If I add a unique image to one of the folders, I am able to use it. Gut feeling is that Xcode is merging the folders????

解决方法

标记的答案是正确的,那是可可豆.这是一个已知问题,目前最好的解决方法(我发现)是使用此方法:

Marked answer is correct, it was cocoapods. This is a known issue and currently the best workaround (i've found), is to use this: https://github.com/CocoaPods/CocoaPods/issues/1546#issuecomment-61907975

推荐答案

如果要编译XCAsset捆绑包,则必须在资产编译时将所有捆绑包指定给XCAsset编译器.为了支持XCAsset文件,可可豆荚将其可以找到的所有资产编译到一个目标中

Turns out if you want to compile XCAsset bundles you have to specify all of them to the XCAsset complier at asset compile time. To support XCAsset files cocoa pods compiles all the assets it can find into one target

请参见 https://github.com/CocoaPods/CocoaPods/pull/1427 #issuecomment-26978591

https://github.com/CocoaPods/CocoaPods/issues/1546 #issuecomment-43137780

您的解决方案是您需要修改./Pods/Target Support Files/Pods-(pod target)/Pods-(pod target)-resources.sh

Your solution is you need to modify any files generated by cocoa pods in ./Pods/Target Support Files/Pods-(pod target)/Pods-(pod target)-resources.sh

有一个看起来像这样的代码块

there is a code block that looks like this

if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ `find . -name '*.xcassets' | wc -l` -ne 0 ]
then
  case "${TARGETED_DEVICE_FAMILY}" in
    1,2)
      TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone"
      ;;
    1)
      TARGET_DEVICE_ARGS="--target-device iphone"
      ;;
    2)
      TARGET_DEVICE_ARGS="--target-device ipad"
      ;;
    *)
      TARGET_DEVICE_ARGS="--target-device mac"
      ;;
  esac
  find "${PWD}" -name "*.xcassets" -print0 | xargs -0 actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
fi

它会编译生成路径中的所有资产目录,因为它目前无法智能地判断哪些资产目录属于哪个目标.您需要删除脚本的这一部分.如果您需要豆荚中的资产目录,则必须手动添加它们.每次运行pod install时,都需要将对此文件的更改还原到该文件.

It compiles all the asset catalogues in the build path as it cant intelligently tell which asset catalogues belong to what target at this point. You need to delete this part of the script. If you need asset catalogues from your pods you'll have to add them manually. You will need to revert changes to this file every time you run pod install.

好消息是你没有生气.玩得开心:D

The good news is you weren't going mad. Have fun :D

这篇关于Images.xcassets打破了目标定律的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆