问题
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).
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.
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.
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>
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>
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:
- I'm not insane
- I've made some simple mistake I just can't see
- This isn't an Xcode bug and will not require the most over elaborate work around man kind has ever seen. Possibly renaming all images to append the target name as well :-(.
Note
I have tried cleaning, building, reseting simulator, deleting derived data etc. Both on simulator and real device.
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????
Workaround
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
回答1:
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
see https://github.com/CocoaPods/CocoaPods/pull/1427#issuecomment-26978591
and https://github.com/CocoaPods/CocoaPods/issues/1546#issuecomment-43137780
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
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.
The good news is you weren't going mad. Have fun :D
来源:https://stackoverflow.com/questions/28716817/images-xcassets-breaking-the-laws-of-targets