Skip to content

Compile .xcassets files from pods #1427

Merged
merged 6 commits into from Oct 16, 2013

6 participants

@ulrikdamm

Currently, if you have a assets catalog in a pod, the file will just get copied over like normal resources. But these needs to be compiled with the actool command, and not just copied, otherwise the resources will be inaccessible. This is a quick change to the resource copy script, which searches for .xcassets files, and compiles them into the final product, if there are any.

@coveralls

Coverage Status

Coverage remained the same when pulling a83f373 on ulrikdamm:master into 23abea7 on CocoaPods:master.

@fabiopelosin
CocoaPods member

Is there a reason why the patch doesn't follow the same approach used for the compilation of core data models?

@ulrikdamm

For those, you need to compile each with one command. For the asset catalogs, you call actool once with all the files, and it compiles the assets.cat file. I don't think there's a way to call it once for each resource, and have it append to the final file.

@fabiopelosin
CocoaPods member

I see your point.

Does this support multiple assets catalogs?

For clarity as I've never used the actool can you post a sample of the command that this script would run?

@fabiopelosin
CocoaPods member

Finally can you add a note to the changelog crediting yourself once we agree on the patch?

@coveralls

Coverage Status

Coverage remained the same when pulling 62245fc on ulrikdamm:master into 23abea7 on CocoaPods:master.

@ulrikdamm

Here's an example of compiling two asset catalogs (ImageCatalog1 and ImageCatalog2). --compile specifies the .app to compile the assets into. The paths for all the asset catalogs are just appended at the end.

actool --output-format human-readable-text --notices --warnings --platform iphoneos \
 --minimum-deployment-target 7.0 --target-device iphone --compress-pngs \
 --compile /Users/username/Library/Developer/Xcode/DerivedData/ProjectName-efxzpshhrjlpszgojsyqjibbtkmo/Build/Products/Debug-iphoneos/ProjectName.app \
 /Users/username/Developer/Project/ImageCatalog1.xcassets \  
 /Users/username/Developer/Project/ImageCatalog2.xcassets

For getting all the asset catalogs, I run find $PWD -name '*.xcassets'.

@fabiopelosin
CocoaPods member

Finally can you add a note to the changelog crediting yourself once we agree on the patch?

Bump!

@epologee

Any ideas about which next Cocoapods version this will be included in?

@coveralls

Coverage Status

Coverage remained the same when pulling 584d30a on ulrikdamm:master into 23abea7 on CocoaPods:master.

@coveralls

Coverage Status

Coverage remained the same when pulling 1dc6981 on ulrikdamm:master into 23abea7 on CocoaPods:master.

@fabiopelosin
CocoaPods member

👍

@fabiopelosin
CocoaPods member

Thanks for the contribution!

@fabiopelosin fabiopelosin merged commit 669f926 into CocoaPods:master Oct 16, 2013
@alloy
CocoaPods member
alloy commented Oct 24, 2013

@epologee Quite soon.

@alloy
CocoaPods member
alloy commented Oct 24, 2013

@ulrikdamm I’m wondering, what happens when somebody already has asset catalogs for her/his own app project? Does actool merge the Archive.car?

@ulrikdamm

Since it can't merge the archives, it runs the command with both the pod catalogs and local catalogs as input, replacing the archive created with only local assets.

@alloy
CocoaPods member
alloy commented Oct 24, 2013

@ulrikdamm Ah my bad, I remembered the command you execute incorrectly. Great, thanks!

@nmccann
nmccann commented Oct 24, 2013

@ulrikdamm , I'm not sure if this is related to your changes or not, but using the latest version (27.1) I encounter the following build errors:

/* com.apple.actool.errors */
/Users/[redacted]/SourceTree/[redacted]/[redacted]/[redacted]/Images.xcassets: error: The output directory "/Users/[redacted]/Library/Developer/Xcode/DerivedData/[redacted]-chzinbggfpvcpjaknqvwofgfkans/Build/Products/Debug-iphonesimulator/AppName." does not exist.

Any idea what may be causing this? The error occurs when building one of the pods, the exact pod that triggers the error seems to vary from project to project, probably based on whichever one it encounters first. In my case it's pod 'HockeySDK', '3.0.0'

@alloy
CocoaPods member
alloy commented Oct 25, 2013

@nmccann Can you modify your copy resources script to do something like the following immediately before the rsync command is called?

mkdir -p "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"
@nmccann
nmccann commented Oct 25, 2013

@alloy Your suggestion helped me realize what was wrong, basically we're using static library targets as per #731 (comment). These static library targets do not define a value for the WRAPPER_EXTENSION build setting, and as a result the script generates an invalid name. In our case at least, I don't think Cocoapods should be trying to copy the *.xcassets file into a directory for the static library targets, but that is what it's trying to do and since that directory does not exist it fails.

I understand that using static library targets to conditionally link with different pods isn't yet officially supported by Cocoapods but perhaps there is some kind of workaround or quick fix for this, any ideas?

@alloy
CocoaPods member
alloy commented Oct 28, 2013

@nmccann To be clear, do you actually use pods that have xcassets or not and is this still being run and leading to issues? I’m guessing we can just skip asset compilation when WRAPPER_EXTENSION is undefined?

/cc @ulrikdamm

@nmccann
nmccann commented Oct 28, 2013

@alloy None of the pods used have xccassets associated with them, so I think your idea of skipping asset compilation when WRAPPER_EXTENSION is undefined should work.

@alloy
CocoaPods member
alloy commented Oct 28, 2013

@nmccann Ace. Could you please file a dedicated ticket with the summary of the issue and solution? Or a patch if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.