I try to build static framework.
So I run following commands:
for device
xcodebuild
-project MyAppLib.xcodeproj
-sdk iphoneos
-target $PRODUCT_FRAMEWORK
-configuration Release clean build
for simulator
xcodebuild
-project MyAppLib.xcodeproj
-sdk iphonesimulator
-target $PRODUCT_FRAMEWORK
-configuration Release clean build
However when I try to run lipo:
lipo -create build/Release-iphonesimulator/MyAppLib.framework/MyAppLib
build/Release-iphoneos/MyAppLib.framework/MyAppLib
-output MyAppLib.framework
I get an error:
fatal error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo:
build/Release-iphonesimulator/MyAppLib.framework/MyAppLib and
build/Release-iphoneos/MyAppLib.framework/MyAppLib have the same
architectures (i386) and can't be in the same fat output file
From Xcode I success to build it but from CLI both have the same structure.
$ file MyAppLib.framework gives me:
MyAppLib.framework: Mach-O universal binary with 4 architectures: [i386: current ar archive] [arm_v7: current ar archive] [x86_64: current ar archive] [arm64]
MyAppLib.framework (for architecture i386): current ar archive
MyAppLib.framework (for architecture armv7): current ar archive
MyAppLib.framework (for architecture x86_64): current ar archive
MyAppLib.framework (for architecture arm64): current ar archive
If I try to run only for one platform, the build is succeeded but I get strange framework that I cannot even explore it:
Edit:
Multiplatform script:
set -e
# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1
RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"
function build_static_library {
# Will rebuild the static library as specified
# build_static_library sdk
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
ONLY_ACTIVE_ARCH=NO \
BUILD_DIR="${BUILD_DIR}" \
OBJROOT="${OBJROOT}" \
BUILD_ROOT="${BUILD_ROOT}" \
SYMROOT="${SYMROOT}" $ACTION
}
function make_fat_library {
# Will smash 2 static libs together
# make_fat_library in1 in2 out
xcrun lipo -create "${1}" "${2}" -output "${3}"
}
# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
# 2 - Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi
# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi
# 4 - Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi
# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"
# If we're currently building for iphonesimulator, then need to rebuild
# to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi
# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"
# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"
# Copy the framework to the user's desktop
ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"
Solution:
You do not have a problem. The MyAppLib.framework that appears after building your project is your static library, containing slices for all required architectures.
No need to use lipo after building your project.
Issue:
Your build script "automatically" builds your target twice, once for devices and once for simulators. Afterwards it merges both build artefacts to one fat lib (make_fat_library) using lipo.
Afterwards it copies the result around to:
#Ensure that the framework is present in both platform's build directories
As a result, you have a fat lib framework in both build directories.
Now you are trying to merge those two (already merged) fat libs. As both contain the same slices you get the error.
Related
I have developed a static framework which is working fine on iOS 11 (both simulator and device) but it is crashing when AFHTTPSessionManager (AFNetworking's manager) is invoked to hit POST request to remote server and gives EXC_BREAKPOINT in the sample application to test developed framework.
I am using Ray's tutorial of creating frameworks to have Library and Aggregate targets setup. Following is the script to compile the framework,
set -e
# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1
RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"
function build_static_library {
# Will rebuild the static library as specified
# build_static_library sdk
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
ONLY_ACTIVE_ARCH=NO \
BUILD_DIR="${BUILD_DIR}" \
OBJROOT="${OBJROOT}" \
BUILD_ROOT="${BUILD_ROOT}" \
SYMROOT="${SYMROOT}" $ACTION
}
function make_fat_library {
# Will smash 2 static libs together
# make_fat_library in1 in2 out
xcrun lipo -create "${1}" "${2}" -output "${3}"
}
# Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
# Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi
# Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi
# Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi
# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"
# If we're currently building for iphonesimulator, then need to rebuild
# to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi
# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"
# Ensure that the framework is present in both platorm's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"
# Copy the framework to the user's desktop
ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"
# Copy the resources bundle to the user's desktop
ditto "${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.bundle" \
"${HOME}/Desktop/${RW_FRAMEWORK_NAME}.bundle"
And architectures which script has allowed are x86_64 and arm64 though it should include armv7 and armv7s too in the allowed architectures.
I know it is related to Aggregate's build framework script (not AFNetworking) but I have tried multiple universal scripts to build it but all tries got fail.
Any help in this regard will be highly appreciated.
Thanks.
Update:
All architectures are in the fat-file after adding armv7s in framework's Architectures but the crash still persists.
I'm trying to create and use a framework in iOS. It was working previously and it works on the simulator but not a newer iPhone 6.
I suspect it has to do with the script, but from what I can see (I copied the script for the internet for the most part) it does have arm64 in it:
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 1
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS='arm64' VALID_ARCHS='arm64' $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS='armv7 armv7s' VALID_ARCHS='armv7 armv7s' $ACTION
# Copy the framework structure to the universal folder (clean it first)
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Smash them together to combine all architectures
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${PROJECT_NAME}.framework/${PROJECT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
Any idea what I need to do to get this to compile for arm64 so it'll run on an iPhone 6+?
I seem to get this error:
Please choose iPhone simulator as the build target.
Command /bin/sh failed with exit code 1
Which it sounds like has to do with a script not running. Since I don't have any scripts in my test project, I went back to my framework and tried setting it to Run script only when installing and re-built my framework, but that still does not appear to be working.
You can't, unless you have the source code to the framework, and can recompile it. (That is your best solution anyway.) It's really that you are now running 64 bit code, and your framework is compiled only for 32 bit code. I did write a hack that allowed you to use previous versions of arm libraries, but I don't think that hack will survive the jump to larger bit size. You can try it if you want: click for hack.
Your script generates that error message and quits (without generating any libraries) whenever you're not building for the iOS simulator. This is the offending code:
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 1
fi
Check your architecture and valid architecture and add $(inherited) to Other Linker Flags.
I want to create a private cocoapod of the output framework built for both simulators and devices.
I have created a Cocoa touch framework in which I have integrated CocoaLumberjack using Cocoapods.
I want to build the framework for all architectures possible (simulator as well as device).
By default the build setting,
'Build Active Architectures Only' is set to (Debug - Yes, Release - No).
As soon as I set this setting for debug to No, the build fails with the following linker error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_DDASLLogger", referenced from:
objc-class-ref in MyManager.o
"_OBJC_CLASS_$_DDLog", referenced from:
objc-class-ref in MyManager.o
"_OBJC_CLASS_$_DDTTYLogger", referenced from:
objc-class-ref in MyManager.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I get it that CocoaLumberjack is available for only active architectures in debug version.
So I switch back the Build active architectures for debug to Yes and build the framework successfully.
To build the framework for all the architectures I am using a run script added in Build phases that also claims to merge the ios-device and ios-simulator build into one. Here is the script:
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 1
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS='arm64' VALID_ARCHS='arm64' $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS='armv7 armv7s' VALID_ARCHS='armv7 armv7s' $ACTION
# Copy the framework structure to the universal folder (clean it first)
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Smash them together to combine all architectures
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${PROJECT_NAME}.framework/${PROJECT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
I check the 'Run script only when installing' checkbox present below the run script. Now I build the framework for Generic iOS device.
Now i click on the Products group present in the Project hierarchy and select the MyFramework.framework file, right click and select show in finder. It opens up the ~/Library/Developer/Xcode/DerivedData/MyFramework-dlpsipmxkqmemwgqrfeovlzgyhca/Build/Products/Debug-iphoneos/MyFramework.framework in finder.
Now, I create a new tag 'MyFramework-v0.0.1' containing the commit where I added MyFramework.framework file.
I go to ~/.cocoapods/repos/MyRepoName/ and create a podspec file MyFramework.podspec as follows:
Pod::Spec.new do |s|
s.name = "MyFramework"
s.version = "0.0.1"
s.summary = "A pod for MyFramework"
s.description = "A pod designed for MyFramework"
s.homepage = "My_Private_Repo_Path"
s.license = { :type => "MIT", :file => "FILE_LICENSE" }
s.authors = { "My_Username" => "my_email_address"
}
s.platform = :ios, "8.0"
s.ios.deployment_target = "8.0"
s.source = { :git => "My_Private_Repo_Path", :tag => 'MyFramework-v'+String(s.version) }
s.requires_arc = true
s.vendored_frameworks = "MyFramework.framework"
s.dependency "CocoaLumberjack"
end
Now when I run the following command in the terminal:
pod repo push MyRepoName MyFramework.podspec
I get the following Error:
Validating spec
-> MyFramework (0.0.1)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use ` --verbose` for more information.
- NOTE | [iOS] xcodebuild: ld: warning: ignoring file MyFramework/MyFramework.framework/MyFramework, missing required architecture i386 in file MyFramework/MyFramework.framework/MyFramework (2 slices)
- NOTE | [iOS] xcodebuild: ld: warning: ignoring file MyFramework/MyFramework.framework/MyFramework, missing required architecture x86_64 in file MyFramework/MyFramework.framework/MyFramework (2 slices)
- NOTE | [iOS] xcodebuild: fatal error: lipo: -remove's specified would result in an empty fat file
[!] The `MyFramework.podspec` specification does not validate.
How to build cocoa touch framework for all devices and simulators, that is dependent on another framework (CocoaLumberjack) added using cocoapods? I need to create a private pod of the output framework.
So basically I found out that I just need to follow these simple steps.
1. Create a cocoa touch framework.
2. Set bitcode enabled to No.
3. Select your target and choose edit schemes. Select Run and choose Release from Info tab.
4. No other setting required.
5. Now build the framework for any simulator as simulator runs on x86 architecture.
6. Click on Products group in Project Navigator and find the .framework file.
7. Right click on it and click on Show in finder. Copy and paste it in any folder, I personally prefer the name 'simulator'.
8. Now build the framework for Generic iOS Device and follow the steps 6 through
9. Just rename the folder to 'device' instead of 'simulator'.
10. Copy the device .framework file and paste in any other directory. I prefer the immediate super directory of both.
So the directory structure now becomes:
- Desktop
- device
- MyFramework.framework
- simulator
- MyFramework.framework
- MyFramework.framework
Now open terminal and cd to the Desktop. Now start typing the following command:
lipo -create 'device/MyFramework.framework/MyFramework' 'simulator/MyFramework.framework/MyFramework' -output 'MyFramework.framework/MyFramework'
and that's it. Here we merge the simulator and device version of MyFramework binary present inside MyFramework.framework. We get a universal framework that builds for all the architectures including simulator and device.
Now, creating a pod for this framework doesn't make any difference. It works like a charm. Please also note that there are run scripts available too to achieve the same functionality, but I spent a lot of time in finding the correct script. So I would suggest you use this method.
XCode 11
First note that you can not use a fat framework with simulator support (x84_64 arch) for publishing to AppStore so you need to make two fat frameworks: one for Release with ARM archs (devices only) and one for Debug - ARM and x86_64 archs.
You can put next scripts to your projects's folder to make fat frameworks from a command line:
Makefile
BUILD_DIR = build
BUILD = #sh build.sh ${BUILD_DIR}
default:
#echo "Build framework makefile"
#echo "usage: make (release | debug | all | rebuild | clean)"
release:
${BUILD} Release YourTargetScheme # <- your target scheme
debug:
${BUILD} Debug YourTargetScheme
clean:
rm -r ${BUILD_DIR}
all: release debug
rebuild: clean all
build.sh
# Debug
set -x
# Params
BUILD_DIR=$1
CONFIGURATION=$2
SCHEME=$3
WORKSPACE=YourWorkspace.xcworkspace # <- your workspace file
DERIVED_DATA_PATH=$BUILD_DIR/DerivedData
# Destinations
IPNONEOS="generic/platform=iOS"
IPNONESIMULATOR="platform=iOS Simulator,name=iPhone 8"
# Build
if [ $CONFIGURATION = "Release" ]; then
xcodebuild \
-quiet \
-showBuildTimingSummary \
-workspace $WORKSPACE \
-configuration $CONFIGURATION \
-scheme $SCHEME \
-derivedDataPath $DERIVED_DATA_PATH \
-destination "$IPNONEOS"
else
xcodebuild \
-quiet \
-showBuildTimingSummary \
-workspace $WORKSPACE \
-configuration $CONFIGURATION \
-scheme $SCHEME \
-derivedDataPath $DERIVED_DATA_PATH \
-destination "$IPNONEOS" \
-destination "$IPNONESIMULATOR"
fi
# Move
FRAMEWORK=$SCHEME.framework
FRAMEWORK_PATH=$BUILD_DIR/$CONFIGURATION/$FRAMEWORK
mkdir $BUILD_DIR/$CONFIGURATION
rm -r $FRAMEWORK_PATH
if [ $CONFIGURATION = "Release" ]; then
mv $DERIVED_DATA_PATH/Build/Products/Release-iphoneos/$FRAMEWORK $FRAMEWORK_PATH
else
mv $DERIVED_DATA_PATH/Build/Products/Debug-iphoneos/$FRAMEWORK $FRAMEWORK_PATH
BINARY_FILE=$FRAMEWORK_PATH/$SCHEME
ARMV7=$FRAMEWORK_PATH/armv7
ARM64=$FRAMEWORK_PATH/arm64
x86_64=$FRAMEWORK_PATH/x86_64
lipo $BINARY_FILE -extract armv7 -o $ARMV7
lipo $BINARY_FILE -extract arm64 -o $ARM64
cp $DERIVED_DATA_PATH/Build/Products/Debug-iphonesimulator/$FRAMEWORK/$SCHEME $x86_64
lipo -create $ARMV7 $ARM64 $x86_64 -o $BINARY_FILE
# Clean
rm -rf $ARMV7 $ARM64 $x86_64
fi
Run one of these commands inside your project folder to build needed frameworks:
make all # Debug and Release frameworks
make release # Release only for devices and AppStore (armv7 and arm64 archs)
make debug # Debug with simulator support (armv7, arm64 and x86_64 archs)
Then you can find your fat frameworks in build directory inside your project's folder.
I can create Framework in XCode using "Aggregate target". Also it's possible to create "Cocoa Touch Framework" in XCode 7.
What is difference between them?
What way is preferable in new project?
I prefer to make Cocoatouch framework.
And finally, run the script to make it universal framework.
You don't need to make it to the aggregate.
FYI, here is the script I'm using now.
I found this script from the web. (I cannot remember the source)
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 0
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS='arm64' VALID_ARCHS='arm64' $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS='armv7 armv7s' VALID_ARCHS='armv7 armv7s' $ACTION
# Copy the framework structure to the universal folder (clean it first)
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Smash them together to combine all architectures
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${PROJECT_NAME}.framework/${PROJECT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
Go to project settings -> build phases and then click the plus button to add new run script.
If you need to support iOS < 8.o then you can't use "Cocoa Touch Framework"
I'm building my own framework by following the guide on site
Create a framework for iOS - RayWenderlich
It works well, but when I integrate the framework on test project, it catches error as "undefined symbol for architecture arm64". When I check the supported architectures by the command
<myframework>.framework xcrun lipo -info <myframework>
it misses 2 architectures armv7s and x86_64
Here is my run script on Aggregate target
set -e
# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1
RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"
function build_static_library {
# Will rebuild the static library as specified
# build_static_library sdk
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
ONLY_ACTIVE_ARCH=NO \
BUILD_DIR="${BUILD_DIR}" \
OBJROOT="${OBJROOT}" \
BUILD_ROOT="${BUILD_ROOT}" \
SYMROOT="${SYMROOT}" $ACTION
}
function make_fat_library {
# Will smash 2 static libs together
# make_fat_library in1 in2 out
xcrun lipo -create "${1}" "${2}" -output "${3}"
}
# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
# 2 - Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi
# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi
# 4 - Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi
# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"
# If we're currently building for iphonesimulator, then need to rebuild
# to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi
# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"
# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"
# Copy the framework to the user's desktop
ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"
I suppose the build error when integrating framework to test project causes by the missing architecture when building framework
Solved, in my case: in the main target (RWUIControls, if you refer to Ray W. post) I added manually the armv7s architecture.
See screenshot below:
if I run the command from the terminal:
xcrun lipo -info RWUIControls
inside the framework folder now I get:
Architectures in the fat file: RWUIControls are: armv7 armv7s i386 x86_64 arm64
It's easy only change the iOS Development Target in the project Info.
In my case I had selected iOS 13 then I changed it to iOS 10 and now I have those Archs -> armv7 i386 x86_64 arm64.
These are the Architectures depending on the iOS device.
armv64: iPhoneX, iPhone 5s-8, iPad Air — iPad Pro
armv7 : iPhone3Gs-5c, iPad WIFI(4th gen)
armv6 : iPhone — iPhone3G
the above if for real devices
i386 : 32-bit simulator
x86_64 : 64-bit simulator