How to make visible internal source code of XCFramework - ios

We are developing a framework for work efficiency.
The framework has a dependency on RxSwift.
So, App has RxSwift in the form of a Dynamic Framework.
So I created XCFramework.
But if I create a framework with XCFramework, I cannot see the internal code.
I hope other departments can also see the internal code of our XCFramework.
I used the following command:
xcodebuild archive \-workspace <ProjectName>.xcworkspace \-scheme ‘<ProjectName>’ \-configuration Release \-destination 'generic/platform=iOS' \-archivePath ./build/<ProjectName>.framework-device.xcarchive \SKIP_INSTALL=NO \BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild archive \-workspace <ProjectName>.xcworkspace \-scheme ‘<ProjectName>’ \-configuration Release \-destination 'generic/platform=iOS Simulator' \-archivePath ./build/<ProjectName>.framework-device.xcarchive \SKIP_INSTALL=NO \BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework \
-framework ./<ProjectName>.framework-device.xcarchive/Products/Library/Frameworks/<ProjectName>.framework \
-framework ./<ProjectName>.framework-simulator.xcarchive/Products/Library/Frameworks/<ProjectName>.framework \
-output ./<ProjectName>.xcframework
I also tried Universal Framework.
The Universal Framework was able to see internal code.
However, an error occurs when running in the simulator.
Could not build Objective-C module 'MyFramework'
Universal Framework Simulator Build Error Image
import UIKit
import RxSwift
import LgIotService
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let a = IotServiceManager()
a.useRxSwift().subscribe(onNext:{ result in
print(result)
})
}
}
I used the following command:
######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
######################
# Build Frameworks
######################
rm -rf "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator"
rm -rf "${BUILD_DIR}/${CONFIGURATION}-iphoneos"
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
######################
# Build Frameworks iphonesimulator - EXCLUDED_ARCHS="arm64"
######################
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} OBJROOT="${OBJROOT}/DependentBuilds" EXCLUDED_ARCHS="arm64" CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} OBJROOT="${OBJROOT}/DependentBuilds" CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1
######################
# Create directory for universal
######################
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
######################
# Copy files Framework
######################
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"
######################
# Make an universal binary
######################
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo
# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
######################
# On Release, copy the result to release directory
######################
open "${BUILD_DIR}"
From Xcode12 or higher, I know that XCFramework is recommended.
Please let me know if there is a way to make the internal source code visible in XCFramework.
And is there any way to solve the error that occurred in Universal Framework?
I tried XCFramework and Universal Framework to make Framework
XCFramework works fine. But I cannot see the internal Source Code.
On the other hand, Universal Framework does not Build in Simulator.

Related

error: accessing build database "/Build/Intermediates.noindex/XCBuildData/build.db": disk I/O error

In our project, we are building universal frameworks and we are able to generate iOS SDK without issue and we are able to integrate without error. But while building iOS SDK (Xcode-> Product-> Build)we are getting the above error and get Build Failed. How to fix this?
I will add the run script here.
# Type a script or drag a script file from your workspace to insert its path.
######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=true
FRAMEWORK_NAME="XXXX"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
PROJECTNAME="XXXX"
######################
# Clean
######################
xcodebuild clean -workspace "${PROJECTNAME}.xcworkspace" -scheme "${PROJECTNAME}"
######################
# Build Frameworks
######################
xcodebuild BITCODE_GENERATION_MODE=bitcode -workspace "${PROJECTNAME}.xcworkspace" -scheme "${PROJECTNAME}" -sdk iphonesimulator -configuration "${CONFIGURATION}" clean build CONFIGURATION_BUILD_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator" 2>&1
xcodebuild BITCODE_GENERATION_MODE=bitcode -workspace "${PROJECTNAME}.xcworkspace" -scheme "${PROJECTNAME}" -sdk iphoneos -configuration "${CONFIGURATION}" clean build CONFIGURATION_BUILD_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneos" 2>&1
######################
# Create directory for universal
######################
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
######################
# Copy files Framework
######################
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"

Facing issue when simpling runing the build and not pressing cleaning issue

I have created a custom framework and made the framework universal-framework for simulator and iphone using following code
echo "project"
#open "${PROJECT_DIR}"
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-iosuniversal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
echo "iphone"
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} -UseModernBuildSystem=NO clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} -UseModernBuildSystem=NO clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1
## Step 2. Copy the framework structure (from iphoneos build) to the universal folder
echo "universal"
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
echo "iphone simulator path"
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
echo "lipo create"
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's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
echo "end"
fi
Removing the unwanted architecture in application when installing it in device by using following script
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[#]}"
rm "${EXTRACTED_ARCHS[#]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
issue which i am facing is the code is getting work only when i clean and build in application. if i simply build or run application without cleaning then it gives me following errors
Lipo: input file must be a fat file when the -extract option is specified
Lipo: can't open input file:frameworks-arm64(No such file or directory)
Rm: frameworks-arm64(No such file or directory)
You just need to remove Run-Script which contains this framework related script from build phases in the project and check is it working or not?
I faced the same issue for one of the projects and it worked for me.
Also, you can refer to this link.

Swift universal framework depending on pod

I'm developing a small Swift framework that depends on Alamofire. I'm using it as an embedded framework of an app belonging to the same workspace and it works perfectly.
The problem arises when I want to build an universal framework with an aggregate target. Then, when executing the script to generate the framework it fails with the message No such module 'Alamofire', referring to an import Alamofire in one of my source files.
This is my Podfile:
platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!
target 'FSIBackend' do
pod 'SwiftLint'
pod 'Alamofire'
pod 'SwiftyJSON'
end
This is the script to generate the framework. It works with other frameworks without Pods dependencies so I assume that is ok:
set -e
# Setup
FRAMEWORK_NAME="${1}"
BUILD_DIR="${SRCROOT}/build"
OUTPUT_DIR="${HOME}/Desktop/"
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework"
rm -rf "${BUILD_DIR}"
rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT_DIR}"
# Build
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"
# Copy the device version of framework to output.
cp -r "${BUILD_DIR}/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}"
# 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 "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6.
cp -r "${BUILD_DIR}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule"
# Delete build.
rm -rf "${BUILD_DIR}"
The question is that I don't know how to build my framework depending on Alamofire. Do I have to create a podspec for my framework and use it via CocoaPods? This is the first time I create a universal framework depending on a pod so I don't know if I'm doing something impossible.
Thank you so much.
Finally I could accomplish it taking into account the advice given from #mag_zbc, thank you.
I had to modify the framework generation this way:
set -e
# Setup
WORKSPACE="${1}"
FRAMEWORK_NAME="${2}"
BUILD_DIR="${SRCROOT}/build"
OUTPUT_DIR="${HOME}/Desktop/"
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework"
CONFIGURATION="${CONFIGURATION}"
rm -rf "${BUILD_DIR}"
rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT_DIR}"
# Build the framework for device and for simulator (using all needed architectures).
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Copy the device version of framework to output.
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}"
# 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 "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6.
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule"
# Delete build.
rm -rf "${BUILD_DIR}"
After generated, and added to the consumer app, the only thing left to do is to use Cocoapods in the consumer app to get Alamofire and SwiftyJSON.

How to build cocoa touch framework for all architectures dependent on other frameworks added using cocoapods?

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.

iOS : Universal framework is creating issue while submitting to app store

We have created one framework and integrated it in my one app. I am able to run and debug the app using this framework but i am receiving below error while submitting to the app store.
Please note that i am using xcode 6.3.
Error: 'Unsupported architecture', The executable for XYZ contains unsupported architecture '[x86_64, i386]'."
I have added below script in settings to Framework code while creating the
framework(Static library) to make it universal.
**Options**
REVEAL_ARCHIVE_IN_FINDER=true
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
`Build Frameworks`
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator -target ${PROJECT_NAME} -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator | echo
xcodebuild -project ${PROJECT_NAME}.xcodeproj -sdk iphoneos -target ${PROJECT_NAME} -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos | echo
#xcodebuild -target ${PROJECT_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" | echo
#xcodebuild -target ${PROJECT_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" | echo
Create directory for universal
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
Copy files Framework
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"
Make fat universal binary
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo
On Release, copy the result to desktop folder
if [ "${CONFIGURATION}" == "Release" ]; then
mkdir "${HOME}/Desktop/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"
cp -r "${FRAMEWORK}" "${HOME}/Desktop/${FRAMEWORK_NAME}-${CONFIGURATION}- iphoneuniversal/"
fi
If needed, open the Framework folder
if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
if [ "${CONFIGURATION}" == "Release" ]; then
open "${HOME}/Desktop/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"
else
open "${UNIVERSAL_LIBRARY_DIR}/"
fi
fi
Can anyone please help me to create framework which i can debug (means run in simulator), run(in device) and also submit to the appstore.
Thanks in advance.
You can't use universal fat binaries with application uploaded to AppStore. If you want to upload with your framework, build it only for device.
You can still use your universal framework, but would have to strip unwanted architecture. i don't try i yet but, i found here a sample of the same problem with solution on striping unwanted architecures. here

Resources