Hello everyone, I hope you are all doing great. I...
# multiplatform
f
Hello everyone, I hope you are all doing great. I’m currently trying to get an existing iOS/tvOS framework to consume a new KMM framework. When a new Kotlin Multi Platform Project (KMM) is created from Android Studio, the wizard gives you the option to choose between CocoaPods or XCFramework integrations (see image). 1. When using CocoaPods a new task named
podspec
is created which generates a
podpsec
file which points to a
.framework
file located in
build/cocoapods/framework/shared.framework
. Even though it’s mentioned there that an XCFramework is built, I don’t know what gradle task we are supposed to run. When running
./gradlew tasks --all
I don’t see any XCFramework related task. So here some questions about the CocoaPods integration: a. What’s the right way to get a framework that can be used for production considering that I won’t release an app but a framework and that I want to include multiple architecture slices (iOS simulator, iOS device, tvOS simulator, tvOS device)? b. Is it possible to get an XCFramework only using the CocoaPods integration? 2. On the other hand, when choosing XCFramework from the wizard only
Debug
and
Release
build types/configurations are available and there doesn’t seem to be an option to add more. Here some questions regarding the XCFramework integration: a. What’s the right way to work for development? Do we need to generate a new XCFramework every time we make a change? b. If the existing framework does not exclude i386 architecture, I will get an error regarding this missing architecture. Does KMM not support i386? The existing framework supports iOS 9 which apparently seems to force the i386 architecture. The architectures property in build settings is set to standard (ARCHS = “$(ARCHS_STANDARD)“). Maybe the right setup should combine both? If so what would be the right way to do this? I’ve tried quite a few different approaches and the best I’ve found so far is to use the
org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
function/initializer which doesn’t allow me to use custom build configurations (Test, Preprod). Neither does the
XCFrameworkConfig
class. I hope I’m being clear and I hope to be asking the right questions. Have a great weekend. Cheers
v
Hi Filipe, For regular development you can choose ‘regular framework’ option or ‘cocoapods’ if your ios project already uses cocoapods. Both options build framework for a specific configuration selected in the Xcode, so you don’s waste time building all the architectures. (seems like there is a mistake in description, in fact it builds Framework, not XCFramework) If you shared module is decoupled from iOS and Android app and you want to distribute it separately then XCFramework might be a good option.
Btw, could you please share the link where you took the screenshot from. I’ll ask to fix it.
f
Hi Viacheslav, first of all, thanks for your answer. From your answer I understand that I’d have to have different (Xcode) targets for development and production since when the framework is added in the “General” -> “Frameworks and libraries” section there’s no option to add both and differentiate between development and production. Regarding the screenshot, I took that from Android Studio, when creating a new “KMM Library” project. Cheers
v
I don’t think you need different configurations in xcode. In normal case, when you develop a mobile app and have shared Kotlin module you just connect your shared module as a regular framework. In that case, Xcode should run embedAndSignAppleFramework gradle task. This task reads Xcode env vars and builds suitable frameworks, for example if you build an app for simulator it will x64 architecture only, if you archive an app for app store it will build a fat framework for required architectures. You can try to create a KMM Application from wizard and see how this integration works. Similarly, you can use cocoapods integration. It works in a similar way and builds architectures Xcode requires it to build. Cocoapods integration may be useful if your ios app already uses it for other dependency, so all your dependencies will be in. one place. In case you want to distribute your shared module as a separate entity to third-party consumers (externally or within the same organisation) you may need XCFrameworks. Because only XCFrameworks allow to combine all possible variants in one, such as X64 simulator, arm 64 simulator, arm64 device and more.
f
Thanks a lot once again for your reply. The thing is, I don’t develop an app but a framework and what I release is a framework. My plan is to consume the KMM framework from an existing framework that contains both business and iOS specific UI code. Do these suggestions still apply in this case? 1. How should Xcode run the 
embedAndSignAppleFramework
Gradle task? Should it be a
Build Phase
script? 2. When using the
embedAndSignAppleFramework
task, how exactly should the framework be added to the framework
target
on Xcode? 3. Where could I find more documentation regarding the
embedAndSignAppleFramework
task? Cheers!
v
Hope this guide answers your questions. If something is still unclear feel free to ask. https://kotlinlang.org/docs/kmm-integrate-in-existing-app.html#connect-the-framework-to-your-ios-project
f
thanks Viacheslav, I’ll take a look at this documentation.