Kotlin 1.5.20: Default iOS integration gradle task for KMM

Are you currently using the packForXcode Gradle task in your KMM project to build the frameworks required by the iOS app? Then, it might be worth updating your Kotlin version to 1.5.20 so as to enjoy the integrated Gradle task embedAndSignAppleFrameworkForXcode that does the same job without you writing a single line of code.

How to migrate to the new approach for an existing project

Follow the following easy steps to migrate.

  • Delete the packForXcode task from your build.gradle(.kts) file of the KMM module.
  • In the Xcode Run Script build step, change packForXcode to embedAndSignAppleFrameworkForXcode and remove all the passed flags. The task will use the Xcode environment configuration and build only the needed artifact automatically.
  • In Xcode build steps, remove everything related to the KMM framework (there should be no mention of it in the Link Binaries or Embed Frameworks sections). In other words, there is no need to add the shared.framework to Frameworks, Libraries and Embedded Content anymore.
  • In Xcode build settings, set Other Linker flags$(inherited) -framework sharedShared here is the name of iOS framework, that is configured in the build.gradle(.kts) file of the KMM module.
  • In Xcode build settings, set Framework Search Path$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)

That’s all!

NB: You may have to update some of your library dependencies once you update your Kotlin version to support the Kotlin update.


Utilizing this new approach does simplify your project configuration by reducing the amount of code in the build.gradle(.kts) file of the KMM Module and also fix a couple of known problems in the previous approach.

Cheers!