37

Let's say I do the following:

  1. Open Xcode 7
  2. File | New | Project | Cocoa Touch Framework
  3. Create "TestFramework" with the Swift language
  4. Create a file Hello.swift with public func hello() { print("Hello") }.

From here, I can build a debug build of the framework (inside the Debug-iphoneos folder), but I cannot figure out how to build the release version of the framework (inside Release-iphoneos). I thought Archive might do it, but it doesn't. Pointers please?

4 Answers4

67

To get a release build, you need to change your scheme settings:

enter image description here Alternatively, create a new scheme for release builds.

Ensure you have a device selected. Not the simulator.

enter image description here

Build your project and you should see that it gets added to this location: (Click the arrow to navigate there in finder) enter image description here

And after drilling down, you should be able to find the release folder with your release framework inside. enter image description here

Beau Nouvelle
  • 6,962
  • 3
  • 39
  • 54
  • 5
    This seems like a poor way to build a release version of a library. You have to change the scheme. Is this because of a bug or is this the intended use? –  Jan 07 '16 at 19:00
  • 1
    This is how it's supposed to be. Being able to choose between the two is useful. For example, perhaps your debug version has network calls that connect to a different endpoint than your release version. Or maybe your debug version has very verbose logging. I believe you can also create more flags than just 'release' and 'debug' flags. Any code you don't want to be in the release version, you can wrap in an "If Debug" statement, and all you have to do is switch schemes. – Beau Nouvelle Jan 07 '16 at 20:57
  • 4
    I agree with @Ana, one should rely on the archive feature instead of dabbling with the run scheme. However, after archiving, I have no idea where the final product is. – Mazyod Oct 12 '16 at 08:55
  • You can right click on the archive in the little window that appears once Xcode has finished archiving and there should be an option to open that location in finder. – Beau Nouvelle Oct 12 '16 at 08:59
  • @BeauNouvelle as Ana said, if this seems to the poor way, i would like to know is there any/ what other way to distribute a release version of a cocoa touch framework? – niczm25 Feb 22 '17 at 13:27
  • 1
    @niczm25 Well you could always write a build script that can output the framework to an easily accessible folder. However, the most common way to distribute frameworks is by setting your project up with cocoa pods, and/or putting it on GitHub. Other devs can then download and compile your framework on their own machine. – Beau Nouvelle Feb 23 '17 at 03:55
  • @BeauNouvelle i am new to ios development so i don't know how start with script, my concern is using your answer, this is still acceptable right? would this work with current version of XCode (v8) without any error? – niczm25 Feb 23 '17 at 06:04
27

This works for me:

Select your framework target then click Product -> Archive. If organizer window does not pop up after successful build of your framework then go to "Build Settings" of your framework target, look for the option "Skip Install" and change it to "No" (and after that Archive again).

Mark Reid
  • 2,611
  • 3
  • 23
  • 45
Leszek Szary
  • 9,763
  • 4
  • 55
  • 62
  • Archiving is working but the outputted Framework is not usable and getting error 'framework not found', any idea? – Goppinath Jan 17 '18 at 10:30
  • Following these steps makes the app integrating the framework not exportable: https://stackoverflow.com/questions/47103464/archive-in-xcode-appears-under-other-items – TomTasche Jun 29 '18 at 09:07
  • After archiving open the generated archive (right click on the xcarchive in finder and select "show contents"). The framework is now in Product -> Library-> Framework folder. – Jochen Holzer Jun 10 '21 at 21:23
5

An alternative to building a framework via the Xcode IDE is to build it from the command line.

You can produce a release build of your framework for iphoneos devices with the following command:

xcodebuild -workspace TestSDK.xcworkspace -scheme TestSDK -configuration Release -sdk iphoneos

Change the value of the -configuration argument from Release to Debug in order to produce a debug build. Change the value of the -sdk argument from iphoneos to iphonesimulator in order to produce a build for Simulator devices.

Note that you may need to provide the -project argument instead of -workspace if your target is part of an Xcode project only and not part of an Xcode workspace. Run the xcodebuild -help command for the full list of xcodebuild options.

If you prefer to archive, you can do that from the command line also, as follows:

xcodebuild archive -workspace TestSDK.xcworkspace -scheme TestSDK -configuration Release -sdk iphoneos -archivePath "TestSDK_Release_iphoneos.xcarchive" SKIP_INSTALL=NO

Note that you can specify SKIP_INSTALL=NO as part of your project or target's Build Settings instead if you prefer.

Lastly, if you want to join up your iphoneos and iphonesimulator builds into a single binary, you can do that with the xcodebuild -create-xcframework command as follows:

xcodebuild -create-xcframework \
    -framework "TestSDK_Release_iphoneos.xcarchive/Products/Library/Frameworks/TestSDK.framework" \
    -framework "TestSDK_Release_iphonesimulator.xcarchive/Products/Library/Frameworks/TestSDK.framework" \
    -output "TestSDK.xcframework"

See here for the official guide to creating an XCFramework.

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
0

When you add the framework to your other Xcode project then you have to add "$(BUILT_PRODUCTS_DIR)" to Build Settings -> Framework Search Paths. This will create Debug when you run project (with Debug) and will create Release version when you archive project. The archive doesn't will create Release version under Products dir but will create Release in "Intermediates.noindex" folder.

feca
  • 1,119
  • 16
  • 14