Instantly share code, notes, and snippets.

Embed
What would you like to do?
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
echo "Building for iPhoneSimulator"
xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build
# Step 1. Copy the framework structure (from iphoneos build) to the universal folder
echo "Copying to output folder"
cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 2. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule"
fi
# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "Combining executables"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"
# Step 4. Create universal binaries for embedded frameworks
#for SUB_FRAMEWORK in $( ls "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks" ); do
#BINARY_NAME="${SUB_FRAMEWORK%.*}"
#lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${SUB_FRAMEWORK}/${BINARY_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
#done
# Step 5. Convenience step to copy the framework to the project's directory
echo "Copying to project dir"
yes | cp -Rf "${UNIVERSAL_OUTPUTFOLDER}/${FULL_PRODUCT_NAME}" "${PROJECT_DIR}"
open "${PROJECT_DIR}"
fi
@eladnava

This comment has been minimized.

Owner

eladnava commented Oct 10, 2016

Based off of https://gist.github.com/atsepkov/1673c2d899470270e3eb313912aafc6f with improvements:

  1. Use {TARGET_NAME}.framework instead of {PROJECT_NAME}.framework
  2. Copy universal framework to Xcode project directory
  3. Fix a few other bugs with Xcode 8
@eladnava

This comment has been minimized.

@donly

This comment has been minimized.

donly commented Mar 9, 2017

Not work for Xcode Version 8.2.1 (8C1002), the copy path was wrong.

SOURCE_FOLDER="${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}"
echo "Copying to output folder:"$SOURCE_FOLDER

$ tail /tmp/YKCenterSDK_archive.log

Copying to output folder:/Library/Frameworks/MySDK.framework
cp: /Library/Frameworks/MySDK.framework: No such file or directory

@omarojo

This comment has been minimized.

omarojo commented Mar 11, 2017

@donly so whats the right path ?

@ronaldho

This comment has been minimized.

ronaldho commented Mar 11, 2017

I had the same trouble but make sure you follow this in the instructions:

Be sure to select MySDK for the Provide build settings from setting and click Close to apply the changes.

@dynamite8

This comment has been minimized.

dynamite8 commented Mar 11, 2017

Hope this helps. I also stumbled on that instruction. You won't have issue of not finding the path once you select your framework.

screen

@dynamite8

This comment has been minimized.

dynamite8 commented Mar 11, 2017

This script worked for me but how can one do this with cocoapods to distribute the framework? Do we have to zip up the framework and upload it to the server for cocoapod distribution or is there a better alternative?

@alessioarsuffi

This comment has been minimized.

@scottcarter

This comment has been minimized.

scottcarter commented Apr 15, 2017

I also had the same error as @donly but I did have the "Provide build settings from" set properly in the Run Script.

My issue:
I found that I did not have to set "Skip install" to No in order to be able to archive (in contradiction to the article), so I left it at Yes.

This was my problem however. As soon as I changed Skip Install to No, I no longer had the "No such file or directory" error.

@dinarajas

This comment has been minimized.

dinarajas commented Jun 27, 2017

In the original script, why step 4 is commented out? Sorry for a newbie question.

@eciftcioglu

This comment has been minimized.

eciftcioglu commented Jul 21, 2017

Hello, I have a problem that unless Bitcode is set to NO the script does not generate the binaries for the simulator and if the bitcode is enabled when I add my framework to a test app I have an error that says bitcode was not enabled by the creator of this framework.

@eladnava

This comment has been minimized.

Owner

eladnava commented Jul 22, 2017

@dynamite8 Nice catch. Yes, you must select your target in the "Provide build settings from" for the script to work.

@dinaraja The script I based this off of included Step 4, but I found it unnecessary, since Xcode already builds for arm and the script builds for the simulator architectures before Step 1.

@eciftcioglu Please try to create a brand new project, following the instructions in my blog post. These instructions will create a 100% reproducible universal binary iOS framework project.

@adelinofaria

This comment has been minimized.

adelinofaria commented Jul 25, 2017

I made it work in Xcode 8.3.3 by replacing ${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH} with ${TARGET_BUILD_DIR}.
Not sure if it's the best approach, but works.

@eladnava

This comment has been minimized.

Owner

eladnava commented Jul 26, 2017

@adelinofaria Thanks for sharing this!

@butterfieldj

This comment has been minimized.

butterfieldj commented Sep 25, 2017

The build is archiving correctly on Xcode 9, but I'm only getting builds for armv7 and arm64 when I check with file and lipo -info. Are there any updates that I'm missing?

@butterfieldj

This comment has been minimized.

butterfieldj commented Sep 26, 2017

Nevermind, it looks like my scheme didn't match up with my project name, once I switched it, the build worked successfully. Thanks for posting this!

@eladnava

This comment has been minimized.

Owner

eladnava commented Sep 26, 2017

@butterfieldj My pleasure!

@abhinav66

This comment has been minimized.

abhinav66 commented Oct 5, 2017

Hi, I have followed all the steps, set Skip Install To No and put in the script and choosen the target in provide build settings, In Xcode 8.3.3, I am still getting only device architectures and not simulator architecture. Can i know how to debug the run script to see if it is working??

@abhinav66

This comment has been minimized.

abhinav66 commented Oct 5, 2017

Never mind i had 2 iphone 6 simulators one for 9.0 and other for 10.3, which was causing the error. Thanks

@therealmyluckyday

This comment has been minimized.

therealmyluckyday commented Oct 11, 2017

When the script executes this command: xcodebuild -workspace "/Users/myuser/Projects/ios/myProj/MyProj.xcworkspace" -scheme "MyProj" -configuration Release -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO VALID_ARCHS='i386 x86_64' BUILD_DIR="/Users/myuser/Library/Developer/Xcode/DerivedData/MyProj-bokoksmsystwiickzjprmvcpgseq/Build/Intermediates.noindex/ArchiveIntermediates/MyProj/BuildProductsPath" BUILD_ROOT="/Users/myuser/Library/Developer/Xcode/DerivedData/MyProj-bokoksmsystwiickzjprmvcpgseq/Build/Intermediates.noindex/ArchiveIntermediates/MyProj/BuildProductsPath" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build I get a build error and the simulator version of the framework doesn't get created:

The following build commands failed:
	MasterObjectLink /Users/myuser/Library/Developer/Xcode/DerivedData/MyProj-bokoksmsystwiickzjprmvcpgseq/Build/Intermediates.noindex/icc.build/Release-iphonesimulator/CardIO.build/Objects-normal/CardIO-i386-master.o
	MasterObjectLink /Users/myuser/Library/Developer/Xcode/DerivedData/MyProj-bokoksmsystwiickzjprmvcpgseq/Build/Intermediates.noindex/icc.build/Release-iphonesimulator/CardIO.build/Objects-normal/CardIO-x86_64-master.o

Obviously failing on my CardIO dependency. However if I run the exact same command in the terminal it compiles successfully and produces the simulator version of the framework. How is that possible? What is different?

@eladnava

This comment has been minimized.

Owner

eladnava commented Oct 11, 2017

@therealmyluckyday I would first check that Xcode environment variables are identical in between the execution environments. Not sure though as this is indeed a very strange issue you are facing.

@zhihuitang

This comment has been minimized.

zhihuitang commented Oct 14, 2017

the script failed, could you have a look? I am using Xcode9 + Swift4

CompileSwiftSources normal i386 com.apple.xcode.tools.swift.compiler
    cd /Users/zhihuitang/repo/ios/MySDK
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -incremental -module-name MySDK -O -whole-module-optimization -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk -target i386-apple-ios11.0 -g -module-cache-path /Users/zhihuitang/Library/Developer/Xcode/DerivedData/ModuleCache -Xfrontend -serialize-debugging-options -swift-version 4 -I /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/ArchiveIntermediates/MySDK/BuildProductsPath/Release-iphonesimulator -F /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/ArchiveIntermediates/MySDK/BuildProductsPath/Release-iphonesimulator -parse-as-library -c -num-threads 8 /Users/zhihuitang/repo/ios/MySDK/MySDK/MySDK.swift -output-file-map /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/Objects-normal/i386/MySDK-OutputFileMap.json -parseable-output -serialize-diagnostics -emit-dependencies -emit-module -emit-module-path /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/Objects-normal/i386/MySDK.swiftmodule -Xcc -I/Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/MySDK-generated-files.hmap -Xcc -I/Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/MySDK-own-target-headers.hmap -Xcc -I/Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/MySDK-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/MySDK-project-headers.hmap -Xcc -I/Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/ArchiveIntermediates/MySDK/BuildProductsPath/Release-iphonesimulator/include -Xcc -I/Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/DerivedSources/i386 -Xcc -I/Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/DerivedSources -emit-objc-header -emit-objc-header-path /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/Objects-normal/i386/MySDK-Swift.h -import-underlying-module -Xcc -ivfsoverlay -Xcc /Users/zhihuitang/Library/Developer/Xcode/DerivedData/MySDK-gvalunhkbddlroanykaqwmqewaty/Build/Intermediates.noindex/MySDK.build/Release-iphonesimulator/MySDK.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/zhihuitang/repo/ios/MySDK
<unknown>:0: error: iOS 11 does not support 32-bit programs
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

** BUILD FAILED **
@eladnava

This comment has been minimized.

Owner

eladnava commented Oct 14, 2017

Hi @zhihuitang,
Please try removing i386 from the script and try again.

This:

ARCHS='i386 x86_64'

Turns to:

ARCHS='x86_64'
@dearkato

This comment has been minimized.

dearkato commented Oct 31, 2017

Hi @eladnava!
I have error when I open file MySDK within the MySDK.framework directory (I followed your lesson):

/Users/user/Library/Developer/Xcode/DerivedData/MySDK-gbtuxxjvrnplhafjblxuxqzrnxba/Build/Products/Debug-universal/MySDK.framework/MySDK ; exit;
➜  ~ /Users/user/Library/Developer/Xcode/DerivedData/MySDK-gbtuxxjvrnplhafjblxuxqzrnxba/Build/Products/Debug-universal/MySDK.framework/MySDK ; exit;
zsh: bad CPU type in executable: /Users/user/Library/Developer/Xcode/DerivedData/MySDK-gbtuxxjvrnplhafjblxuxqzrnxba/Build/Products/Debug-universal/MySDK.framework/MySDK
@eladnava

This comment has been minimized.

Owner

eladnava commented Nov 1, 2017

Hi @dearkato,
You are not supposed to actually run the MySDK file, it is a binary meant for either the iOS simulator or a physical iOS device.

@omerblu

This comment has been minimized.

omerblu commented Nov 5, 2017

Hi @eladnava

Can you update the script to enable bitcode support for all 4 slices?

@eladnava

This comment has been minimized.

Owner

eladnava commented Nov 6, 2017

Hi @omerblu,
Not entirely sure how to do that unfortunately. We do inject the ENABLE_BITCODE flag, it doesn't affect all slices?

Also, check your Xcode project settings for bitcode enabled.

@saravanankk

This comment has been minimized.

saravanankk commented Jan 24, 2018

Hi @eladnava

I created framework project in Swift4 and Xcode 9.
My Framework project have some other dependency that are written in both swift and Objective-C, Example: SSZipArchive , XCGLogger , iOSDFULibrary. How Do i create the zip file in this case with all dependency. Please advise me on this. Thanks in advance

@eladnava

This comment has been minimized.

Owner

eladnava commented Jan 25, 2018

Hi @saravanankk,
If these dependencies are on CocoaPods, simply mention them in the Podspec:

s.dependency 'SomeOtherPod'

If not:
https://stackoverflow.com/questions/22447062/how-do-i-create-a-cocoapods-podspec-that-has-a-dependency-that-exists-outside-of

@saravanankk

This comment has been minimized.

saravanankk commented Jan 25, 2018

Hi @eladnava
Thanks for the quick response i will try and let you know

@saravanankk

This comment has been minimized.

saravanankk commented Jan 25, 2018

Hi @eladnava

I tried the way you suggest for s.dependency.
Dependency pods are seems to be installing in the example project. I can see them and I can able to import into the example app project. But My own framework is not seems to installed I am not able to import that module.

#My example app pod file is as below

target 'LibCocoapodTest' do
use_frameworks!
platform :ios, '9.0'
pod 'Mypod', :path => '../Mypod'
end

#Mypod folder contain the podspec as below

Pod::Spec.new do |s|
s.name = "Mypod"
s.version = "0.0.9"
s.summary = " Mypod Library."
s.author = { "" => "" }
s.license = "None"
s.license = { :type => "None (0)", :file => "LICENSE"}
s.homepage = 'http://Mypod.com/'
s.summary = 'Chunky bananas!'
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.11"
s.default_subspec = 'Binary'
s.source = {
:http => 'http://localhost:8000/Mypod.framework.zip'
}
s.subspec 'Binary' do |binary|
binary.vendored_frameworks = Mypod.framework'
end
s.dependency 'SSZipArchive', '> 2.1'
s.dependency 'XCGLogger', '
> 6.0'
s.dependency "iOSDFULibrary"
end

Note : I am creating my Mypod.framework zip file using Xcode archive framework project (source code) reside in separate location
and it has different podspec with local file references

Any idea why MyFramework pod is not installing also in the example app Mypod create local development pod folder but nothing inside

thanks

@KompoD

This comment has been minimized.

KompoD commented Mar 22, 2018

Thanks for script @eladnava, but when Finder opened my framework path I didn't find *.framework file :(
Can you help me?

SOLVED: I forget to setting "Skip Install" to "No" :)

@mkeremkeskin

This comment has been minimized.

mkeremkeskin commented Mar 29, 2018

Hey everyone,

When I was using this script for the first time few months ago it was working. But right now it doesn't. I finally found the issue. This script tries to find iPhone 6 as simulator. If your XCode doesn't have iPhone simulator, the framework appears after few minutes and binary doesn't have simulator architectures. In that case change change simulator name to available one. in my case I change it to iPhone 8

xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8' ONLY_ACTIVE_ARCH=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

@MithunMadhav1112

This comment has been minimized.

MithunMadhav1112 commented Apr 10, 2018

I followed the steps in the guide. When I run 'file' command, �it prints only the following message

- Mach-O 64-bit dynamically linked shared library arm64

Where have I gone wrong ?

@mknippen

This comment has been minimized.

mknippen commented Apr 11, 2018

Here's something I found helpful:

When following the blog post, on Xcode 9.3, I had to do the hint outlined earlier:
change ARCHS='i386 x86_64' to ARCHS='x86_64'

This is because iOS 11 doesn't support i386.

However, changing the Deployment Target back to an older version of iOS, and this worked fine. Since many users writing frameworks want to support older versions of iOS, I would suggest moving the deployment target back to an earlier version (iOS 8 & 9 are tested and working for me). Then, no changes are needed to the script.

@mknippen

This comment has been minimized.

mknippen commented Apr 11, 2018

@MithunMadhav1112 I had the same issue until changing the deployment target. See above.

@mknippen

This comment has been minimized.

mknippen commented Apr 25, 2018

Upon further review, neither of these options appears to create a build that allows me to submit to the App Store. Using the option above works great for simulator and device, but when submitting to the App Store, I get several errors:

ITMS-90087: Unsupported Architectures. The framework contains unsupported architectures [x86_64, i386]'.
ITMS-90635: Invalid Mach-O format. The format in X.framework is not consistent with the Mach-O in the main bundle. The main bundle Mach-O contains armv7(bitcode) and arm64(bitcode), while the nested bundle Mach-O contains X86_64ALL(machine code). Verify that all of the targets for a platform have a consistent value for the ENABLE_BITCODE build setting.
ITMS-90209: Invalid Segment Alignment. The app binary at DIR/X.framework/X does not have proper segment alignment. Try rebuilding the app with the latest Xcode version.

@lottadot

This comment has been minimized.

lottadot commented Jun 19, 2018

@mknippen You'd have to strip the x86_64 and/or i386 from the frameworks you're using in order to submit to the App Store. Often you'll see people add a build phase script item to check if the current build configuration is RELEASE and then if so iterate through frameworks that are linked in and remove the x86 slices from them. You may find it easier if you do this with an app-store-specific build scheme.

@porcokang

This comment has been minimized.

porcokang commented Jul 11, 2018

Add below code If want to zip sequence into the script.

# Step 6. Create zip
cd ${PROJECT_DIR}

mkdir Build
cp LICENSE Build
cp -rf ${FULL_PRODUCT_NAME} Build

rm -rf "${FULL_PRODUCT_NAME}.zip"
zip -r "${FULL_PRODUCT_NAME}.zip" Build
rm -rf ${FULL_PRODUCT_NAME} Build
@Jane930525

This comment has been minimized.

Jane930525 commented Jul 20, 2018

Didn't find the framework generated under universal framework but was found in both simulator and iPhone individually

@nick3389

This comment has been minimized.

nick3389 commented Aug 7, 2018

@eladnava the script seems to not be working in XCode 10... It seems that the .framework does not exist under Release-universal folder. Is there any suggestion?

@rob-keepsafe

This comment has been minimized.

rob-keepsafe commented Aug 7, 2018

A few things:

  1. Thanks for posting this! It was really helpful
  2. This script can also be done completely using the command line's archive option on xcodebuild; doing it as a post-archive in Xcode's schemes is pretty opaque because you don't get a sense of build progress like you do in the command line
  3. You aren't lipo'ing the dSYM files into a universal dSYM but it's easy to add. Personally, I'd want to ensure all frameworks are distributed with dSYM files so crashes can be symbolicated

Here's an example script from where we're creating a universal iOS .framework and .framework.dSYM and bundling that with a macOS build into one zip file that can be used in a .podspec

Custom script (with dSYM lipo step as well): https://github.com/KeepSafe/ObjectiveRocks/blob/frameworks/build_universal_framework.sh
Podspec example: https://github.com/KeepSafe/ObjectiveRocksFramework/blob/master/ObjectiveRocksFramework.podspec

Another custom example: https://github.com/AudioKit/AudioKit/blob/master/Frameworks/build_frameworks.sh

@nick3389

This comment has been minimized.

nick3389 commented Aug 8, 2018

@rob-keepsafe we ran this script from the project's folder? Also, does this produce a universal framework for both simulators and devices? Thank you!

@fer662

This comment has been minimized.

fer662 commented Sep 17, 2018

@nick3389 seeing the same result with xcode 10.

@BalaKarunakaran

This comment has been minimized.

BalaKarunakaran commented Sep 18, 2018

The Script is not working in Xcode 10. Its opens OUTPUTFOLDER, But the Universal Framework is not generated in that folder. Anything need to change in the Script. @eladnava.

@nick3389

This comment has been minimized.

nick3389 commented Sep 18, 2018

@eladnava @fer662 @BalaKarunakaran

It seems that in XCode 10, the folder under Release-universal path does not contain the {YOUR_FRAMEWORK}.framework file but its contents. I solved it by replacing this line under echo "Copying to output folder":

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

with this one:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}" "${UNIVERSAL_OUTPUTFOLDER}/"

Please, confirm that it works for you too.

@BalaKarunakaran

This comment has been minimized.

BalaKarunakaran commented Sep 18, 2018

@nick3389 Great, Its working fine. 👏

@donygeorgek

This comment has been minimized.

donygeorgek commented Sep 27, 2018

This used to work in Xcode 8.3.3
It is not working in Xcode 9.4.1. The generated framework does not have the i386 & x86_64 files. Any update needed in script?

@macbellingrath

This comment has been minimized.

macbellingrath commented Oct 2, 2018

@nick3389 👍 thanks!

@Jignesh1805

This comment has been minimized.

Jignesh1805 commented Oct 6, 2018

Hi all of you ,
Please can you help me .
Regarding third party framework add in podspec file .

@IvanovDeveloper

This comment has been minimized.

IvanovDeveloper commented Oct 18, 2018

@eladnava @fer662 @BalaKarunakaran

It seems that in XCode 10, the folder under Release-universal path does not contain the {YOUR_FRAMEWORK}.framework file but its contents. I solved it by replacing this line under echo "Copying to output folder":

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

with this one:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}" "${UNIVERSAL_OUTPUTFOLDER}/"

Please, confirm that it works for you too.

It's work for xcode 10

@ignaval

This comment has been minimized.

ignaval commented Oct 22, 2018

@eladnava @fer662 @BalaKarunakaran

It seems that in XCode 10, the folder under Release-universal path does not contain the {YOUR_FRAMEWORK}.framework file but its contents. I solved it by replacing this line under echo "Copying to output folder":

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

with this one:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}" "${UNIVERSAL_OUTPUTFOLDER}/"

Please, confirm that it works for you too.

I actually had to change a different line for this to work on Xcode 10 (Version 10.0 (10A255)). I added a missing target name. But kept the original line you mentioned changing. I just changed:

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"

for:

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"

and it worked correctly.

@canisterexister

This comment has been minimized.

canisterexister commented Oct 26, 2018

If still not working check AlexM answer https://stackoverflow.com/a/52873099/4311935

@antonc27

This comment has been minimized.

antonc27 commented Nov 21, 2018

Just want to notice that script will not work as is if you have different target and product names (e.g., target MyLib_iOS and product MyLib.framework). This can be fixed by using $PRODUCT_NAME instead of $TARGET_NAME (except of -scheme parameter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment