IOS CBL and Catalyst

I have an iPad app based on CBL Mobile 1.x. I would love to use Catalyst to port to the Mac.

What is involved in getting the CBL Mobile framework built for Catalyst?

Is there any plans to add support for this?

T

1 Like

There are no plans to do anything to 1.x anymore, and no plans to add this additional architecture to 2.x.

This is possible using a new Xcode 11 framework format called XCFrameworks. See the corresponding WWDC session 416 titled: “Binary Frameworks in Swift” for details. It’s very similar to building a fat binary framework, but you don’t need to merge the framework contents by hand. And you can also mix and match platforms.

I’ve successfully build an XCFramework version of CBL 2.5 as a test, but I had to make changes to account for deprecations in iOS 13 and a few APIs that are unavailable on the Catalyst platform. The former changes will likely need to be made anyway to support Xcode 11 / iOS 13.

I suspect XCFrameworks will be the preferred way to deliver a single framework bundle that supports both the simulator and iOS devices, potentially along with Catalyst.

I’m very happy to see XCFrameworks – the inability to have multi-platform frameworks has been a real pain in the butt to us since 2011 (for doing device vs simulator builds.)

That said, I haven’t had any time yet to learn about them or adapt our Xcode frameworks to generate them. And we wouldn’t be able to release any XCFramework binaries until at least September, since they require Xcode 11 and we can’t release software built with beta dev tools.

@lightandshadow: I assume you can’t just add Mac frameworks to a Catalyst build target? Since it is building a Mac application, after all? That would be the quick and easy way to make this work today.

@jens I’m so happy you are at least hoping to make this work. It’s very important to me and most of the other CBL developers I know!

Todd

3 Likes

I have yet to document this clearly, as it was somewhat of a trial and error process. But the key changes were to add the additional “x86_64 i386” architectures to the assigned.xconfig for the target, then use xcodebuild to create archives for all three platforms. I was creating a Swift only app, so I built the Swift version of CBL.

xcodebuild archive -scheme "CBL Swift" -destination "generic/platform=OS X" -destination "generic/platform=ios" -destination "generic/platform=iOS Simulator" SKIP_INSTALL=NO

This builds three archives, that show up in the Organizer window, from which you can extract the resulting frameworks. I ended up copying them into subfolders since they were named the same, then used xcodebuild again to create the xcframework.

xcodebuild -create-xcframework -framework ./iosdevice/CouchbaseLiteSwift.framework -framework ./iossimulator/CouchbaseLiteSwift.framework -framework ./macos/CouchbaseLiteSwift.framework -output CouchbaseLiteSwift.xcframework

This xcframework can be added under the Frameworks, Libraries, and Embedded Content section under the General tab for the target. It should be listed as both “macOS + iOS” in the platforms column. At this point, you can build for a device, the simulator or your Mac, if you’re checked the Mac option under the Devices section.

1 Like

Cool! Pull requests welcome :wink:

I have a 2.5 branch that works, but I’ll want to recreate with just the minimal number of changes necessary. I suspect there is a more direct route, as opposed to the wandering path I took to get there.

I’d like to also get this working with 1.x as my primary project has yet to migrate to 2.x. However, we currently use a custom build of 1.4 that cherry picks a commit from 1.4.1.

+1 on the 1.4x support!

T

For 1.x, we run a build phase script which executes BuildFatLibrary.sh to generate a fat library, but the script for building library per platform.

You can create an independent script to generate XCFramework by building CBL-iOS from CI iOS scheme and CBL-MacOS from CI MacOS scheme and combining them. You will need to disable the build phase that builds the fat library as well.

A huge thanks to the community for helping with this.
However, I was unable to get it to work myself. Is there any fork that can be built without changing the scripts on your own?
I am also a bit confused with which branch to try, given that there is the xcframework, xcode11Beta and the current 2.5 release line.

I was able to build the three frameworks. However, in the end your approach has resulted in the following error for me:

No ‘swiftinterface’ files found within ‘XXX/Projects/couchbase-lite-ios/iosdevice/CouchbaseLiteSwift.framework/Modules/CouchbaseLiteSwift.swiftmodule’.

Do you have any suggestions on how to fix this? Also what exactly did you mean by:

add the additional “x86_64 i386” architectures to the assigned.xconfig

At what point did you receive that error? I managed to create an xcframework from the individual .framework builds, but never got a chance to test it as my project has a number of other framework dependencies that have yet to be updated.

Also what exactly did you mean by:

add the additional “x86_64 i386” architectures to the assigned.xconfig

I was referring to the .xconfig assigned to the iOS target. You’ll need to officially add that architecture as a “first class” citizen, as opposed to ending up with a x68_64 slice as a means to provide support for the iOS simulator. While they are the same platform, Catalyst seems to consider them separately.

I received the error already when running the xcodebuild -create-xcframework command.

Did you add that manually,m direclty in the .CBL-Swift.xcconfig file or in the Xcode project’s CBL Swift target as a ‘Valid architecture’?

Anyone tried?
a. switching to xcframework branch
b. run the sh Scripts/build_xcframework.sh -s "CBL Swift" -o ~/Desktop/out

Yes, unfortunately there is an error.
It says: While building for Mac Catalyst, no library for this platform was found in 'CouchbaseLiteSwift.xcframework'

Is there any indication as to when you will be able to provide an official fix for the Catalyst situation? Other dependencies we use, such as Moya, Kingfisher, Bugsnag or Mixpanel all have working betas via Cocoapods already.

Currently the script will only include
(i)generic/platform=iOS,
(ii)generic/platform=iOS Simulator, and
(iii)generic/platform=macOS

There was not much of a documentation found for mac catalyst specific configuration to archive. “platform=macOS,arch=x86_64,variant=Mac Catalyst” results in, unable to find destination errors in OSX Catalina and OSX Mojave. Hoping to get more clear picture in coming days.