@file:OptIn(ExperimentalSwiftExportDsl::class) import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask import org.jetbrains.kotlin.gradle.swiftexport.ExperimentalSwiftExportDsl import org.jetbrains.kotlin.gradle.tasks.CInteropProcess import org.jetbrains.kotlin.konan.target.linker plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidLibrary) } val unzipDir = layout.buildDirectory.file("unpacked") kotlin { compilerOptions { freeCompilerArgs.add("-Xexpect-actual-classes") } // val xcFrameworkName = "ProjectName" // val xcf = XCFramework(xcFrameworkName) val firebaseAuthDir = unzipDir.map { File(it.asFile, "Firebase/FirebaseAuth") } listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { iosTarget -> val dirName = when (iosTarget.name) { "iosX64" -> "ios-arm64_x86_64-simulator" "iosArm64" -> "ios-arm64" "iosSimulatorArm64" -> "ios-arm64_x86_64-simulator" else -> "ios-arm64" } iosTarget.compilations.getByName("main") { @Suppress("unused") val FirebaseAuth by cinterops.creating { this.packageName = "com.google.firebase.auth" compilerOpts( "-framework", "FirebaseAuth", "-F${File(firebaseAuthDir.get(), "FirebaseAuth.xcframework/$dirName")}", "-F${File(firebaseAuthDir.get(), "FirebaseAuthInterop.xcframework/$dirName")}", "-fmodules" ) } } iosTarget.binaries.all { // Linker options required to link to the library. linkerOpts("-L${firebaseAuthDir.get()}", "-lFirebaseAuth") } // iosTarget.binaries.framework { // baseName = xcFrameworkName // // // Specify CFBundleIdentifier to uniquely identify the framework // binaryOption("bundleId", "online.smsvirtual.${xcFrameworkName}") // xcf.add(this) // isStatic = true // } } swiftExport { // Set the root module name moduleName = "ProjectName" // Set the collapse rule // Removes package prefix from generated Swift code flattenPackage = "project.name" linkTask { // not working // this.libraries.from(files("build/libs/shared-iosArm64Cinterop-FirebaseAuthMain.klib")) } // linkTask { // println("TARGET==================>>>$target<<<======================") // println("outputfile==================>>>$outputFile<<<======================") // println("outputkind==================>>>$outputKind<<<======================") // println("basename==================>>>${baseName}<<<======================") // println("all==================>>>${this}<<<======================") // // this.outputFile // binary.compilation.cinterops.all { // println("TARGET cinterop==================>>>$target<<<======================") // println("DEF===================>>>$definitionFile<<<======================") // // packageName = "com.google.firebase.auth" // // compilerOpts( // "-framework", // "FirebaseAuth", // "-F${File(firebaseAuthDir.get(), "FirebaseAuth.xcframework")}", // "-fmodules" // ) // // linkerOpts("-L${firebaseAuthDir.get()}", "-lFirebaseAuth") // } // } // not working // e: ❌ Swift Module Resolution Error //The following modules specified in swiftExport { export() } were not found in the resolved components: unspecified:unspecified:unspecified //Solution: Please check the module name and ensure it is correct. // export(files("build/libs/shared-iosArm64Cinterop-FirebaseAuthMain.klib")) // not working // export("firebase:firebase-ios-sdk:10.29.0:Firebase@zip") // Provide compiler arguments to link tasks configure { freeCompilerArgs.add("-Xexpect-actual-classes") } } sourceSets { commonMain.dependencies { // put your Multiplatform dependencies here implementation(libs.ktor.client.core) implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.serialization.kotlinx.json) implementation(libs.androidx.datastore) implementation(libs.androidx.datastore.preferences) api(libs.genovich.components.action) implementation(libs.genovich.components.combine) implementation(libs.genovich.components.parallel) implementation(libs.genovich.components.whileactive) api(libs.genovich.components.oneof) api(libs.genovich.components.uistate) } commonTest.dependencies { implementation(libs.kotlin.test) } iosMain.dependencies { implementation(libs.ktor.client.darwin) } } } val zipArchives by configurations.creating dependencies { // https://github.com/firebase/firebase-ios-sdk/releases/ //noinspection UseTomlInstead zipArchives("firebase:firebase-ios-sdk:10.29.0:Firebase@zip") } val unzipFirebase by tasks.registering(Copy::class) { from(zipArchives.files.map { zipTree(it) }) into(unzipDir) } tasks.withType { dependsOn(unzipFirebase) } val createXCFrameworkZip by tasks.registering { // dependsOn(tasks.named("assembleSMSVirtualCoreXCFramework")) } version = "0.0.2" tasks.withType { val xcFrameworkTask = this val zipTask = tasks.register("${name}Zip") { dependsOn(xcFrameworkTask) archiveBaseName = if ("Release" in name) { "NameRelease" } else { "NameDebug" } archiveVersion.set(version.toString()) destinationDirectory = layout.buildDirectory.dir("zips") from(xcFrameworkTask.outputs.files.singleFile.parent) // I need *.xcframework dir here } createXCFrameworkZip.configure { dependsOn(zipTask) } }