Search code examples
kotlin-multiplatform

Failing to generate libraryname.xcframework in kotlin multiplatform mobile (KMM)


I was trying to generate the XCFramework with Kotlin 1.5.31 containing the targets for iOSArm64 and iOSX64 . With the below build.gradle.kt , it generates a FatFrameworks . I’m failing to generate XCFrameworks .

import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
    kotlin {
        val xcFramework = XCFramework(libName)
        android()
        ios {
            binaries.framework(libName) {
                xcFramework.add(this)
            }
        }
    
        sourceSets {
            val commonMain by getting
            val commonTest by getting {
                dependencies {
                    implementation(kotlin("test-common"))
                    implementation(kotlin("test-annotations-common"))
                }
            }
            val androidMain by getting {
                dependencies {
                    implementation("com.google.android.material:material:1.2.1")
                }
            }
            val androidTest by getting {
                dependencies {
                    implementation(kotlin("test-junit"))
                    implementation("junit:junit:4.13")
                }
            }
            val iosMain by getting
            val iosTest by getting
        }
     }

And also I have included the tasks in build.gradle.kts :

tasks {
register(“buildDebugXCFramework”)
register(“buildReleaseXCFramework”)
register(“publishDevFramework”)
register(“publishFramework”)
}

This is the output I got : fatframeowrks generated but not the libraryname.xcframeworks

If Any suggestions to generate XCFrameworks with targets iOSArm64 and iOSX64 ? , it would be helpful , Thank you .


Solution

  • I think that following the documentation might help here. Please set library name by the baseName option and build the final XCFramework by running assembleXCFramework Gradle task.

    import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
        kotlin {
            val xcFramework = XCFramework()
            android()
            ios {
                binaries.framework() {
                    baseName = "libName"
                    xcFramework.add(this)
                }
            }
    ...