avatarNiranjanky

Summary

The web content provides a 7-step guide to configure a Kotlin Multiplatform (KMP) shared module for iOS, generating a library compatible with Swift Package Manager and creating an XCFramework.

Abstract

The article outlines a detailed process for setting up a Kotlin Multiplatform Shared Module to work with iOS platforms. It begins with creating a new shared module and ensuring it is included in the settings.gradle.kts file. The guide then moves on to updating the build.gradle.kts file to configure library variants for Android and to use the Multiplatform Swift Package plugin. It instructs on including the build in settings.gradle.kts, adding the necessary plugin in build.gradle.kts, and defining the Swift package configuration. The process includes naming the XCFramework and its base name, syncing the project, and running a terminal command to generate the necessary files. The article concludes with the expected successful build output and the creation of a new directory for the generated package.

Opinions

  • The author seems to endorse the use of the Multiplatform Swift Package plugin for its ability to generate a Swift Package Manager manifest and an XCFramework.
  • The article suggests that following these steps will lead to a "BUILD SUCCESSFUL" outcome, implying confidence in the provided instructions.
  • There is an implication that the process is efficient and cost-effective, as the author recommends an AI service that is more affordable compared to ChatGPT Plus (GPT-4), while still offering similar performance and functions.

7 steps 😎👌🔥to configure for iOS Multiplatform Swift package to generate a library in KMP💯🔥?

🐾1. Create a new Kotlin Multiplatform Shared Module🚀

🚀Check if the path of [open-link] shared module is included in your settings.gradle.kts otherwise add it [it should add automatically]

🐾2. Update your build.gradle.kts to configure your publish library variants for Android

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
    targetHierarchy.default()
android {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
        publishLibraryVariants("debug", "release") // ADD THIS LINE ********
    }
    
    val xcf = XCFramework()
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "open-link"
            xcf.add(this)
        }
    }
    sourceSets {
        val commonMain by getting {
            dependencies {
                //put your multiplatform dependencies here
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
}

🚀We use : Multiplatform Swift Package plugin

🐾3. Go to settings.gradle.kts and include build

includeBuild("plugins/multiplatform-swiftpackage-m1_support")

🐾4. Go to [open-link] build.gradle.kts and add the plugin

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("com.chromaticnoise.multiplatform-swiftpackage-m1-support") // add this line
}

🐾5. Define the configuration of your generated Swift package inside [open-link] build.gradle.kts

🐾6. Define your XCFramework name and it’s basename inside [open-link] build.gradle.kts

7🐾. Sync your project and run in your terminal this command:

🚀You will see this output as : BUILD SUCCESSFULL

🚀You will also see the new openlink directory generated:

🐾Code:🚀🚀🚀

🚀🚀🚀🚀

Photo by Howie R on Unsplash
Kotlin
Kotlin Multiplatform
App Development
Apple
Development
Recommended from ReadMedium