-->

Universal custom iOS framework using Xcode 6.4

2019-06-16 05:59发布

问题:

I have created a custom iOS framework using Xcode 6.And I tried many scripts for making the framework universal(for simulator and device).But none of them worked for me.Please suggest me a way to create a custom universal framework for iOS in Xcode 6.

回答1:

To merge two binaries into a universal binary through the terminal:

First compile the device binary, then compile the simulator binary separately.

Locate both binaries. If you want to check which architectures are compiled into each you can run this command in the terminal:

lipo -info /path/to/binary

Example output:

Architectures in the fat file: /path/to/binary are: armv7 arm64

Now you can merge both binaries into one:

lipo -create /path/to/simulator/binary /path/to/device/binary -output /path/to/output/binary

The output binary will have both simulator and device architectures.



回答2:

as per your question to make custom universal framework you need to follow this steps or visit “http://www.raywenderlich.com/65964/create-a-framework-for-ios” as have made framework referring raywenderlich.

1.) Create a project.

2.) Add new target to your project by selecting Cocoa Touch Static Library. (For more reference visit: http://www.raywenderlich.com/65964/create-a-framework-for-ios)

3.) Now you need to do is set your static library as active scheme. Make sure you have added “arm64” in Build Settings in the tragets library.

4.) Select iOs device and make build. But for that you need to add script below to make it universal for all devices.

Script :

# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
UNIVERSAL_OUTPUTFOLDERx64=${BUILD_DIR}/${CONFIGURATION}-universalx64

# Step 1. Build Device and Simulator versions
xcodebuild -target DKHelperLib ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target DKHelperLib -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target DKHelperLib -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 BUILD_DIR="${UNIVERSAL_OUTPUTFOLDERx64}" BUILD_ROOT="${BUILD_ROOT}"

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a" "${UNIVERSAL_OUTPUTFOLDERx64}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"

# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
Hope this script will help you.



回答3:

To build and distribute frameworks:

In the framework project:

  1. Set the build setting for the target (and for the project, just to be safe) 'Build Active Architectures only' to NO. We want to build all architectures so that the binary can be used in all supported devices, not just the one we happen to build for. Depending on your deployment target (and as a consequence of that, the devices you support), you might need to add the architecture ARMv7s
  2. Build for simulator and build for device, this will produce two frameworks in the derived data folder.

In Terminal:

  1. Find the derived data path for the project. Look for the folder 'Build->Products'. Inside it should be '-iphoneos' and '-iphonesimulator'. Inside each is a .framework folder. Copy one of those to some nice folder. From each of those .frawework folders, copy the binary that is in there to one folder.
  2. In terminal run the command 'lipo -create -output <outputName> <binaryFromiphoneos> <binaryFromiphonesimulator>'. This will create a fat binary with all architectures for both simulator and devices. Replace the one in the copied .framework directory with the newly generated one.

To use the framework in another app:

  1. Select the Project in the Project Navigator, select the target, and select 'General' tab.
  2. drag the .framework folder onto where it says 'Add embedded binaries here'.
  3. In the build settings of the target, add the path to the .framework folder to 'Framework Search Paths'.
  4. Import files in your source code using #import <frameworkName/frameworkName.h>