Conditionally build app with different asset catalogs

后端 未结 1 454
醉话见心
醉话见心 2020-12-28 17:59

My Xcode project is setup in a way that has multiple configurations, allowing me to use the same code base for different variations of my app, but have unique elements in ea

相关标签:
1条回答
  • 2020-12-28 18:12

    This is what you can do to make this work:

    • Add a separate asset catalog per configuration, just as you would normally add an asset catalog to your project. Let's assume for this example we call these catalogs MediaForDebug.xcassets, MediaForAdHoc.xcassets and MediaForRelease.xcassets
    • Make sure the newly created asset catalogs are all member of your target (so DO NOT exclude them here, we'll do that later on)
    • Now, if not already added to your build settings, add a custom EXCLUDED_SOURCE_FILE_NAMES User-Defined setting.
    • See the screenshot below for the values to be set for this User-Defined setting.

    EXCLUDED_SOURCE_FILE_NAMES for config dependant asset catalogs

    By doing this, Xcode will only compile the appropriate asset catalogs, and ignore the others. I've tested this on one of our projects, and it works as intended.

    Good luck!

    REMARK: If you are using CocoaPods, you might run into troubles because CocoaPods adds a build step of its own to compile your assets, and those of your dependencies into on .car file. See https://github.com/CocoaPods/CocoaPods/issues/1546 for the discussion on this issue. TL;DR: make sure this step doesn't execute in your build phase, or edit the CocoaPods script they execute to not do the asset building.

    UPDATE 1/19/2019: With the latest stable Xcode (10.1) and Cocoapods (v1.5.3) they work out of the box with the solution above. No need to alter the Cocoapods scripts or build steps, just set EXCLUDED_SOURCE_FILE_NAMES as described.

    0 讨论(0)
提交回复
热议问题