Creating a universal framework using Xcode 8?

My iOS platform for my company is designed to work on a real iOS device. This structure is currently being created as an additional goal in the Xcode project, which also creates the application. (This makes it relatively easy to debug the structure.)

Recently, we received requests to make it work in the simulator. Now I can do it, and the next step will be to create a compiled version that works both on a real device and in a simulator. Unfortunately, I could not find any material indicating that someone did this using Xcode 8. There are materials explaining how to use older versions of Xcode, but what works in one version of Xcode may not work or be appropriate in a later version. (We already had one way to create a universal framework for us.) I tried using several pre-Xcode 8 scripts, but none of them worked.

Has anyone been able to create a universal infrastructure for iOS using Xcode 8? If so, how can this be done?

Thanks in advance for any help anyone can provide.

Aaron Adelman

+5
source share
3 answers

This is possible since I am currently developing universal frameworks on iOS, watchOS and tvOS on Xcode 8.

The way I do this is to create an Aggregate target (cross platform) and add a run script to my build phase. script basically compiles iOS target for iphonesimulator and iphoneos

After that, a new binary file is created that combines both of them (lipo -create -output)

Could you post the current build script to create a universal framework so that I can lead you to what you are doing wrong?

Bear in mind that the script may not be your problem here, your problem may be to create the right architectures, your architectures, or even how you sign the goal. At the moment, I recommend leaving the option “Automatically manage subscription” in the general settings of your target goal and manually configure your training profiles and certificates.

Run script:

#!/bin/sh UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}/iOS" # Step 1. Build Device and Simulator versions on iOS xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' clean build xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}" -sdk iphoneos clean build # Step 2. Copy the framework structure (from iphoneos build) to the universal folder cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/iOS" # Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}" # Step 4. Convenience step to copy the framework to the project directory mkdir -p "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS" cp -R "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework" "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS" # Step 6. Create .tar.gz file for posting on the binary repository cd "${TMPDIR}" # We nest the framework inside a Frameworks folder so that it unarchives correctly tar -zcf "${PROJECT_NAME}.framework.tar.gz" "${PROJECT_NAME}/Frameworks/" mv "${PROJECT_NAME}.framework.tar.gz" "${PROJECT_DIR}/" # Step 7. Convenience step to open the project directory in Finder #open "${PROJECT_DIR}" 

Bear in mind that I set the Build Build Architecture to only NO in the build settings, also valid architectures are set as arm64, x86_64, i386, armv7, armv7s. Architecture - $ {ARCHS_STANDARD} armv7s.

I also set the user-defined installation bit code to BITCODE_GENERATION_MODE. With this build setting, I will definitely create binaries with bit code enabled.

+13
source

build a versatile / live iOS / tvOS infrastructure

https://github.com/unchartedworks/universalbuild

Application:

universalbuild (-p | --project name.xcodeproj) (-s | --scheme schemename) (-c | --configuration configurationname)

Example:

 git clone https://github.com/cruisediary/Pastel.git cd Pastel universalbuild -p ./Pastel.xcodeproj -s Pastel -c Debug 
+3
source

Run the script to create a generic structure (no recursion)

 #!/bin/sh UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # Next, work out if we're in SIM or DEVICE if [ "false" == ${ALREADYINVOKED:-false} ] then export ALREADYINVOKED="true" if [ ${PLATFORM_NAME} = "iphonesimulator" ] then xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build else xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build fi # Step 2. Copy the framework structure (from iphoneos build) to the universal folder cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/" # Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule" fi # Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}" # Step 5. Convenience step to copy the framework to the project directory cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}" # Step 6. Convenience step to open the project directory in Finder open "${PROJECT_DIR}" fi 
+1
source

Source: https://habr.com/ru/post/1257776/


All Articles