banner



link binary with libraries optional

Breaking Changes with Xcode 12 and XCFramework

Recently, mobile developers have struggled when integrating binary frameworks in their iOS apps. Does this Xcode error look familiar?

Edifice for iOS Simulator, but the linked and embedded framework 'MyFramework.framework' was built for iOS + iOS Simulator.

The reason for this error stems from Apple'due south introduction of M1 fries in the latest Macs. This policy conclusion introduced a side consequence of breaking functionality in binary distribution in Xcode 12. Previously, in Xcode 11, you would get compiler warnings, but your build would still work. That is no longer the case, and the writing is on the wall for the old mode of distributing binaries.

In this post, we'll cover the following topics:

  • How Apple'southward new hardware created this problem
  • How XCFramework is Apple'southward solution
  • How this fits into Apple's thousand program
  • Troubleshooting steps for Xcode 12 and XCFrameworks

How Apple's new Hardware Created This Problem

In November 2020, Apple started releasing Macs with a new class of hardware called the M1, which is a CPU that uses the arm64 architecture. Traditionally, Macs had CPUs that used x86-64. Newer iPhones also apply the arm64 compages, and this is not a coincidence. This consolidation into one CPU compages brings many amazing benefits for Apple tree and their users.

The biggest benefit is the ability to have cantankerous-platform codebases.

  • For Apple, they can build and test i file system module, ane UIKit module, etc., and they will run on both iPhone and Macs. This allows Apple's teams to share lawmaking and exam coverage.
  • For developers, their iOS apps can now run on Macs with very few changes. They can address an unabridged new market without doing any piece of work.
  • For users, they are able to use any iPhone app on their Mac.

Additionally, there are significant functioning and power efficiency improvements in M1 compared to whatsoever existing architectures.

This all sounds swell, and then what is the problem with having Macs and iPhones share the same CPU architecture?

The problem stems from the previous fashion of linking binary frameworks. These frameworks were shipped as "fatty" frameworks, meaning a vendor would build a single framework that contained all the required architectures. Historically, that would mean a single binary file had slices similar the following:

  • arm7 or arm64 for iPhone
  • x86-64 for Macs

The linker would option i of the architectures to use at build fourth dimension depending on the hardware destination. Since the three languages are all separate, it was easy to have dissimilar rules for simulator versus device. In other words, since the architectures for iPhones did non overlap with the architecture for Macs, the linker would never go tripped upwards over which binary to use for a given target.

Now, however, the respective binary file would have slices like the following:

  • arm64 for iPhone
  • arm64 for Mac

They have the same architecture proper name, simply the lawmaking for each target is very different. The iOS Simulator has unlike rules than the iPhone, and you cannot run a binary built for i on the other. The previous manner to link binary frameworks, lipo, is unable to deal with a merged binary containing multiple binaries that share the same architecture.

That's why this error shows up:

Building for iOS Simulator, but the linked and embedded framework 'MyFramework.framework' was built for iOS + iOS Simulator.

The binary framework contains different lawmaking for the same architecture in multiple places, and Xcode doesn't know how to handle it.

How XCFramework Is Apple's Solution

XCFramework is Apple'due south answer to the puzzle described to a higher place. In XCFramework, yous no longer build a single framework with multiple architectures. Instead, you build 1 small-scale framework for each combination of architecture and target and store information technology in its own binder. Your meridian-level XCFramework folder would then have folders similar ios-arm64, ios-arm64-simulator, etc. Each of these folders is its ain framework, complete with headers, modules, and binary.

This division into individual frameworks means you no longer take to spend time merging then stripping platform binaries when linking. For vendors, it also ways you can distribute a single XCFramework containing all your target platforms. With lipo, you were forced to limit your framework to only incorporate unique architectures regardless of the number of platforms you wanted to back up.

How This Fits into Apple tree'southward Thou Program

Apple receives, hosts, processes, and sends all the code that users ultimately download from the App Shop. And that is a lot of code. Anything they can practise to reduce this number equates to less time and money spent on their end and less bandwidth required on downloads for users.

Many improvements here are strictly win-win. Apple'due south introduction of Bitcode is a great instance:

  • Apple tree can compile your app to be optimized for target devices and operating system versions.
  • Apple can recompile your app later to take advantage of specific hardware, software, or compiler changes.
  • Apple tree can reoptimize your app without the need to submit a new version to the App Store.
  • Apple can reduce the download size for users past removing unneeded lawmaking.

Ultimately, the shift to using XCFrameworks is an improvement along the same lines equally Bitcode. Apple'southward goal is to reduce the amount of code that developers send their fashion, which allows them in plow to exist e'er more than efficient.

One has to wonder if this is at least in office a jab from Apple against binary frameworks, given the lack of information and transparency provided to help developers seamlessly transition from lipo frameworks to the new XCFrameworks. Later on all, open up-source frameworks that compile to Bitcode take non had any wrenches thrown their style with Xcode 12. Maybe Apple hopes vendors suffer enough headaches with clients during this transition to potentially reconsider how they provide their software. Apple may view this as a step in the direction they ultimately want u.s.a. to go…

Plenty speculation. Let'south now get over some troubleshooting steps if you are a vendor or developer having difficulty with recent versions of Xcode.

Troubleshooting Steps for Xcode 12 and XCFrameworks

We'll get over the 4 principal ways of implementing dependencies and how to troubleshoot issues with binary frameworks and Xcode 12.

Transmission

When using Xcode 12 or newer, you should use XCFrameworks. For Xcode 11 or older, you need to use lipo fat frameworks. Starting in Xcode 12.3, you cannot use lipo frameworks. Soon, Apple will crave all developers to use Xcode 12 for lawmaking signing, at which betoken vendors that take not updated their binaries to XCFrameworks will not be able to be released in new app versions.

Swift Parcel Managing director

Swift Package Manager only started fully supporting binary frameworks of whatsoever kind in Xcode 12.2. Thus, developers who use vendor binaries must be on at least Xcode 12.2. There are no SPM options for older Xcode versions due to bugs in Apple tree'southward binary implementation.

CocoaPods

CocoaPods implemented XCFramework support earlier than most dependency managers. However, it is nevertheless recommended to upgrade to 1.10.one, or the latest pod utility.  You can check the pod version by typing pod --version into the command line. Anything lower than 1.nine.3 will not piece of work.

Additionally, y'all too need Xcode 12.two or newer for XCFramework support. So a programmer using CocoaPods needs at least Xcode 12.2 AND pod 1.10.one.

Note: you might need to deintegrate an XCFramework in lodge to get things working. That process works like this:

  1. Remove the XCFramework line from your podfile
  2. Run pod update and it will exist removed
  3. Re-add together the XCFramework line
  4. Run pod update again

Carthage

The Carthage squad has not yet shipped XCFramework support.  On their issues page they say even when available it will not support binary XCFrameworks.  Therefore, you should look that Carthage will never support SDKs as XCFrameworks.

For developers who use Carthage, you probably will need to install XCFrameworks manually.

Summing It All Upwardly

If yous recently started having trouble integrating binary frameworks, you are not alone. The shift from Xcode eleven to Xcode 12 has a breaking change regarding XCFrameworks and previous lipo binary frameworks. Apple is requiring the future of binary frameworks to be XCFramework. If you are a vendor, this means you should prioritize making the transition. Nosotros don't know the exact appointment Apple will enforce Xcode 12 for code signing, but when they do, developers and vendors need to be prepared.

How Embrace Helps Mobile Teams

Embrace is an observability and programmer analytics platform built for mobile teams. We are a 1-stop shop for your mobile app's needs, including fault debugging and monitoring performance and feature releases.

Want to meet how Embrace tin help your team grow your app with best-in-course tooling and earth-class back up? Asking a customized demo and see how nosotros assistance teams set and exceed the KPIs that matter for their business!

Request a demo

Free Trial

Source: https://blog.embrace.io/xcode-12-and-xcframework/

Posted by: parrishbegaid.blogspot.com

0 Response to "link binary with libraries optional"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel