Step by Step build a Kotlin Multiplatform Library (SDK) — Part 2

SianLoong
3 min readAug 29, 2021

In the previous article we talked about Android setup, and today we will continue on the iOS setup.

iOS Platform Support

Before Kotlin 1.5.30

After the release of Kotlin 1.5.30, there have been some significant changes for iOS support. As you can see, before Kotlin 1.5.30, we just need to define iosMain in our build.gradle.kts file, because every 64-bit software under iOS arm64 machine will run under Rosetta.

After Kotlin 1.5.30

On Kotlin 1.5.30 onward, we need to define iosArm64Main and iosX64Main inside our build.gradle.kts’s sourceSets. The keyword dependsOn indicates that iosArm64 and iosX64 will use the dependencies of commonMain as well.

If you are interested in the Kotlin 1.5.30 release, you may go here for further information.

Configuration for iOS support

build.gradle.kts
  1. Make sure you set the ios keyword inside kotlin lambda.
  2. Define iosX64Main for iOS 64 bit support inside sourceSets lambda.
  3. Define iosArm64Main for iOS arm64 support inside sourceSets lambda.
  4. Add iosMain and wrap it with iosX64Main and iosArm64Main.
  5. Publish to Maven Local.
  6. Verify there are x64 and arm64 distribution in your local .m2 folder. The naming convention is following <package-name>-(ios|iosarm64|iosx64).
Distribution on .m2

After we finished setup Android and iOS, is time to get ready to publish our artifacts to Maven Central.

Publish to Maven Central is not straightforward as NPM publication, it required certain steps to follows. If you want a quick solution, maybe you can try this plugin out.

Ok, enough for today. We will continue on the next article for Maven Central publication. If you don’t want to miss out, kindly follow me on Medium. 😊

Part 1 — https://sianloong90.medium.com/step-by-step-build-a-kotlin-multiplatform-library-sdk-part-1-e973bdbfa55d
Part 2 — https://sianloong90.medium.com/step-by-step-build-a-kotlin-multiplatform-library-sdk-part-2-1d3a2f58dce1

--

--

SianLoong

Frontend most of the time. Sometime backend. Sometime low-level.