How to build universal framework to work with iOs simulators and real devices

Hi everyone!

Today I'm going on to describe how to create universal framework for iOs simulators and real devices.

  1. First of all make sure Automation manage signin has been disabled. You can do it in the target geniral settings.
  2. Choose Team name and Singing Cectificate for debug and release build signing.
  3. Then open the terminal and go to root project folder. Root project folder - the folder is containing projectName.xcodeproj.
  4. Create sh build file
    touch build.sh
  5. Open the script using any suitable method and add following script
    #!/bin/bash
    
    FRAMEWORK=$1
    
    BUILD=build
    FRAMEWORK_PATH=$FRAMEWORK.framework
    
    # iOS
    rm -Rf $BUILD
    rm -f $FRAMEWORK.framework.tar.gz
    
    xcodebuild archive -project $FRAMEWORK.xcodeproj -scheme $FRAMEWORK -sdk iphoneos SYMROOT=$BUILD
    xcodebuild build -project $FRAMEWORK.xcodeproj -target $FRAMEWORK -sdk iphonesimulator SYMROOT=$BUILD
    
    cp -RL $BUILD/Release-iphoneos $BUILD/Release-universal
    cp -RL $BUILD/Release-iphonesimulator/$FRAMEWORK_PATH/Modules/$FRAMEWORK.swiftmodule/* $BUILD/Release-universal/$FRAMEWORK_PATH/Modules/$FRAMEWORK.swiftmodule
    
    lipo -create $BUILD/Release-iphoneos/$FRAMEWORK_PATH/$FRAMEWORK $BUILD/Release-iphonesimulator/$FRAMEWORK_PATH/$FRAMEWORK -output $BUILD/Release-universal/$FRAMEWORK_PATH/$FRAMEWORK
    
    tar -czv -C $BUILD/Release-universal -f $FRAMEWORK.tar.gz $FRAMEWORK_PATH $FRAMEWORK_PATH.dSYM
  6. You can run script using following command:
    sh build.sh projectName
  7. If everything passed ok you can find universal framework by path build/Release-universal/ 
  8. If you get some errors during script is running then make sure your project compiles via XCode without any problems. After that script should work without any issues.
  9. If you have compilatin issue add to project's "Build Settings / Framework Search Paths" 
    $(PLATFORM_DIR)/Developer/Library/Frameworks
  10. And set "No" to "Build Settings / Enable bitcode"

Have a good day!

Enjoy!