Managing Static Library project as a module like Framework on iOS project in Xcode4

前端 未结 3 1334
孤城傲影
孤城傲影 2021-01-06 16:18

Many people including me trying to make a kind of Static Library framework for iOS to archive some kind of modularity. Framework is best way to do this, but it doesn\'t prov

3条回答
  •  余生分开走
    2021-01-06 16:40

    Solution.

    1. Goto Project or Target's Build Settings.
    2. Find Public Headers Folder Path. (definition name = PUBLIC_HEADERS_FOLDER_PATH)
    3. Set it as YourLibrary.framework/Headers. I have used ${PRODUCT_NAME}.framework/Headers for automatic syncing with project name.
    4. Goto Build Phases and find Copy Headers step.
    5. Move all required headers to Public pane.

    Now all header files will be formed like Framework and copied with product binary. IDE will copy all of them as a unit into some temporary folder like app's build folder. So referencing app project can use the headers automatically.

    This is a trick. The created directory structure is not real framework. Because it doesn't contain any binary. However we don't need real framework to archive just this functionality. IDE works with frameworks without any binary. And I don't want to hack IDE without documentation about internal structure.


    This works well, however you'll experience some problem when you Archive. This happens because Xcode4 behaves specially when Archiving. Here's workaround.

    1. For each embedded library project, SKIP_INSTALL = YES in target build settings.
    2. For final product project, FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts". Take care about this setting should be set only for Release build mode.

    Now it'll be archived well.


    At the case of cross platform library, there can be many projects for many platforms. But sometime Xcode will show some product as red color even it compiled successfully.

    This is a bug of Xcode. IDE display depends SDKROOT of Project build setting. So if you set the SDKROOT differently on Target, it won't work. You can check the the product will become black color after changing the SDKROOT of the Project build setting. See this Open Radar entry for details.

    http://openradar.appspot.com/9636211

    If you wish to fix this bug, please report this to Apple's Radar. Duplicated bugs will make attention of Apple. Just copy & paste my report :)

提交回复
热议问题