How to archive an app that includes a custom framework?

后端 未结 4 620
离开以前
离开以前 2020-12-14 03:35

I have an xcode framework project that I\'ve created, which I can compile into a myframework.framework file. After compiling, I drag this framework into the Fra

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 04:04

    You actually don't need to put it in the "embedded binaries" section. You only need it in the "linked frameworks and libraries section. Make sure that your framework is a Universal Framework (meaning it can compile for all architectures), and make sure you have the right compiler flags set (-ObjC if your framework has any categories etc) There may be some other things you need to set as well like "Other C Flags" if your framework includes any c code and you want to enable bitcode in your client app then you should put "-fembed-bitcode" in your framework Other C Flags. Those were the things I needed to do to get my framework app to the store. I think its a just a misconception that you need to put this in embedded binaries as well to get it to archive for the store.

    This is the build script I use to generate the universal framework. It builds right to my desktop. You can uncomment section 8 if your framework is in Swift. You want to create an aggregate target and add this as a run script in build phases.

    # Merge Script
    
    # 1
    # Set bash script to exit immediately if any commands fail.
    set -e
    
    # 2
    # Setup some constants for use later on.
    FRAMEWORK_NAME="MyFramework"
    
    # 3
    # If remnants from a previous build exist, delete them.
    if [ -d "${SRCROOT}/build" ]; then
    rm -rf "${SRCROOT}/build"
    fi
    
    # 4
    # Build the framework for device and for simulator (using
    # all needed architectures).
    xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos"
    xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator"
    
    # 5
    # Remove .framework file if exists on Desktop from previous run.
    if [ -d "${HOME}/Desktop/${FRAMEWORK_NAME}.framework" ]; then
    rm -rf "${HOME}/Desktop/${FRAMEWORK_NAME}.framework"
    fi
    
    # 6
    # Copy the device version of framework to Desktop.
    cp -r "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${HOME}/Desktop/${FRAMEWORK_NAME}.framework"
    
    # 7
    # Replace the framework executable within the framework with
    # a new version created by merging the device and simulator
    # frameworks' executables with lipo.
    lipo -create -output "${HOME}/Desktop/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
    
    # 8
    # Copy the Swift module mappings for the simulator into the
    # framework.  The device mappings already exist from step 6.
    #cp -r "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${HOME}/Desktop/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule"
    
    # 9
    # Delete the most recent build.
    if [ -d "${SRCROOT}/build" ]; then
    rm -rf "${SRCROOT}/build"
    fi
    

    Once your framework is on the desktop, if you go inside of it there will be a text document with the same name as your framework. If you navigate to that and run the command "lipo -info" on it in terminal you should get the following output:

    Architectures in the fat file: MyFramework are: armv7 armv7s i386 x86_64 arm64 
    

提交回复
热议问题