Elyes Ben Salah
07/10/2021, 6:40 PMimport org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
//kotlin("native.cocoapods")
id("com.android.library")
id("com.squareup.sqldelight")
}
kotlin {
android()
ios {
binaries {
framework {
baseName = "shared"
}
}
}
// Block from <https://github.com/cashapp/sqldelight/issues/2044#issuecomment-721299517>.
val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
if (onPhone) {
iosArm64("ios")
} else {
iosX64("ios")
}
println(targets.names)
println(System.getenv("SDK_NAME"))
sourceSets {
....
val iosMain by getting {
dependencies{
implementation("com.squareup.sqldelight:native-driver:1.5.0")
implementation("io.ktor:ktor-client-ios:${Versions.ktor}")
}
}
val iosTest by getting{
dependencies {
implementation("io.ktor:ktor-client-ios:${Versions.ktor}")
}
}
}
}
android {
.....
}
sqldelight {
......
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)