← Back to list

How to compile in same .a file or .framework in M1 and Intel Simulator?

Problem statement:

Ashish Awasthi · 2023-09-15 11:28 · 0 claps · 2.9 min read
#xcframework #universal-library #swift #simulator #ios
Open on Medium ↗
Wiki topics: 📱 · Mobile Development 📚 · Books & Reading

How to compile same .a file or .framework in M1 and Intel Simulator?

Problem statement:

I intend to distribute a compiled library to my customers. The library may be in the form of a .a file or a .framework file. However, if I provide the library from an M1 Mac machine, it will not compile on an Intel-based simulator with the x86_64 architecture, and vice versa.

  1. When compiling the SDK on both M1 and Intel systems and selecting the device, no issues will arise. This is due to the fact that both systems, M1 and M2, share the same arm64 architecture.
  2. Issue occurs specifically when attempting to use an Intel simulator-built framework in an M1 Simulator, or vice versa.
  3. Intel simulator runs on x86_64 architecture, while the M1 Simulator runs on arm64 architecture.

Solution:

  1. We can create a single framework called .xcframework, which will contain x86_64, arm64 for devices, and arm64 for simulators on M1 processors.
  2. We can accomplish this by executing a few commands.

Create framework with help of bash script manually .

Script written in file called generate_ios_lib_frameworks.sh and execute from project path

sh generate_ios_lib_frameworks.sh

Example: Library name: API-iOS

Create framework with manual Commands on terminal

Archive for simulator Intel, M1 simulator with respective arch.

Before running below commands. Change setting of Your Project

Project target-> Build Settings-> BUILD_LIBRARY_FOR_DISTRIBUTION = YES Project target-> Build settings-> Skip Install = NO

Step 1. Create simulator archive for arch x86_64 and arm64 for both simulator

xcodebuild archive \
-scheme API-iOS \
-archivePath ./builds/sim-x86_64-arm64.xcarchive \
-sdk iphonesimulator \
-arch arm64 -arch x86_64 \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

Step 2. Create Device archive for arch arm64 means for device

xcodebuild archive
-scheme API-iOS \
-archivePath ./builds/ios-arm64.xcarchive \
-sdk iphoneos \
-arch arm64 \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

Step 3. Get API-iOS.framework from archived folders

Builds/sim-x86_64-arm64.xcarchive/ -> Show package content product … get framwork Builds/ios-arm64.xcarchive-> Show package content product … get framework

Create one folder called frameworks/sim-intel-m1

Create another folder called frameworks/ios

Step 5. Create XC framework from simulator arch x86_64 and arm64

xcodebuild -create-xcframework -framework ./builds/Frameworks/ios/API_iOS.framework

-framework ./builds/Frameworks/sim-intel-m1/API_iOS.framework -output ./builds/Frameworks/API_iOS.xcframework

API_iOS.xcframework framework will be created succesfully at this path /builds/Frameworks/API_iOS.xcframework

Final script for creating framework


echo "Remove directory if exist"

dirname='./builds'

if [ -d "$dirname" ]; then
    echo "$dirname exists and is a directory."
     echo "$dirname Removing"
    rm -rf builds
else
    echo "$dirname does not exist."
fi

scheme_name="API-iOS"

skip_install=false 
code_signing_required=false
code_sign_identity_name=""
build_library_for_distribution=true 

for ARGUMENT in "$@"
do
   KEY=$(echo $ARGUMENT | cut -f1 -d=)

   KEY_LENGTH=${#KEY}
   VALUE="${ARGUMENT:$KEY_LENGTH+1}"
   export "$KEY"="$VALUE"
done

echo "Scheme Name: $scheme_name"
echo "Skip Install: $skip_install"
echo "Build Library For Distribution: $build_library_for_distribution"
echo "Code Signing Required: $code_signing_required"
echo "Code Signing Identity Name: $code_sign_identity_name"

echo "Archiving for Apple and Intel simulator Architecture"
xcodebuild archive \
-scheme $scheme_name \
-archivePath ./builds/sim-x86_64-arm64.xcarchive \
-sdk iphonesimulator \
-arch arm64 -arch x86_64 \
 SKIP_INSTALL=$skip_install \
 BUILD_LIBRARIES_FOR_DISTRIBUTION=$build_library_for_distribution

echo "Archiving for Device Architecture which is same"
xcodebuild archive \
-scheme $scheme_name  \
-archivePath ./builds/ios-arm64.xcarchive \
-sdk iphoneos -arch arm64 \
 SKIP_INSTALL=$skip_install \
 BUILD_LIBRARIES_FOR_DISTRIBUTION=$build_library_for_distribution
 STRIP_STYLE=non-global \
 STRIP_INSTALLED_PRODUCT=YES \
 CODE_SIGN_IDENTITY="" \
 CODE_SIGNING_REQUIRED=NO \
 CODE_SIGN_ENTITLEMENTS="" \
 CODE_SIGNING_ALLOWED=NO

echo "Replaceing - with _ Because command creating framework Like this API_iOS.framework\
 Remove below schema doesn't contain -"

scheme_name="${scheme_name//-/_}"

simulator_framework_path=./builds/sim-x86_64-arm64.xcarchive/Products/Library/Frameworks/$scheme_name.framework
echo "Simulator frameworkPath: $simulator_framework_path"

device_framework_path=./builds/ios-arm64.xcarchive/Products/Library/Frameworks/$scheme_name.framework
echo "Divice frameworkPath: $device_framework_path"

xcframework_path=./builds/$scheme_name.xcframework

xcodebuild -create-xcframework \
-framework $simulator_framework_path \
-framework $device_framework_path \
-output $xcframework_path

echo "$scheme_name.xcframework has been generated at path: $xcframework_path"

echo "Zip framework folders"

cd builds
echo "Current Directory"
pwd 
echo "Directory Content"
ls 
echo "Create Zip file"

zip -r ./$scheme_name.zip ./$scheme_name.xcframework

cd ..

echo "Printing contents of directory"
for entry in builds/*
do
  echo "$entry"
done #

Just run Simple command with default scheme name: API-iOS

// Just run
sh scripts/generate_ios_lib_frameworks.sh
// you can also run like this 
sh scripts/generate_ios_lib_frameworks.sh scheme_name = "API-iOS"
// you can also run like this, Other Param also pass like this
sh scripts/generate_ios_lib_frameworks.sh scheme_name = "API-iOS"

FAQ:

If you are getting below error just ignore

Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore 2022–09–09 13:00:23.446 xcodebuild[35874:5285241] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore

If your getting error swift interface package missing

Do this and again start from step 1

Project target-> Build settings-> BUILD_LIBRARY_FOR_DISTRIBUTION = YES Project target-> Build settings-> Skip Install = NO

Conclusion

If you enjoyed reading this post, please share and give some claps so others can find it 👏👏👏👏👏 !!!!


메타데이터
post_id
6fc5e5c2fc30
slug
how-to-compile-in-same-a-file-or-framework-in-m1-and-intel-simulator-6fc5e5c2fc30
url
https://medium.com/@awasthi027.ashish/how-to-compile-in-same-a-file-or-framework-in-m1-and-intel-simulator-6fc5e5c2fc30
canonical_url
https://medium.com/@awasthi027.ashish/how-to-compile-in-same-a-file-or-framework-in-m1-and-intel-simulator-6fc5e5c2fc30
author_url
https://medium.com/@awasthi027.ashish
status
ok
fetched_at
2026-06-21 19:25:17