Created
August 5, 2021 17:53
-
-
Save bmc08gt/bf5fea9a1b7863a73b20f5f715e89fab to your computer and use it in GitHub Desktop.
Shared KMM gradle script for generating a FAT swift package supporting physical devices and simulators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | |
plugins { | |
kotlin("multiplatform") | |
id("com.android.library") | |
kotlin("plugin.parcelize") | |
id("com.apollographql.apollo3") version "3.0.0-dev13" | |
id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.3" | |
} | |
version = "1.0" | |
repositories { | |
mavenLocal() | |
google() | |
mavenCentral() | |
maven( "https://oss.sonatype.org/content/repositories/snapshots/") | |
} | |
kotlin { | |
android() | |
if (project.hasProperty("fulliOS").not()) { | |
val buildForDevice = project.findProperty("kotlin.native.cocoapods.target") == "ios_arm" | |
if (buildForDevice) { | |
iosArm64("ios") | |
} else { | |
iosX64("ios") | |
} | |
} else { | |
//here will creat xcframework contains arm64&x64 | |
ios { | |
binaries { | |
framework { | |
baseName = "PlanolyShared" | |
export("co.touchlab:kermit:0.1.9") | |
transitiveExport = true | |
} | |
} | |
} | |
} | |
multiplatformSwiftPackage { | |
packageName("PlanolyShared") | |
swiftToolsVersion("5.3") | |
targetPlatforms { | |
iOS { v("12") } | |
} | |
buildConfiguration { | |
release() | |
} | |
} | |
sourceSets { | |
val commonMain by getting { | |
kotlin.srcDir("src/commonMain/graphql") | |
dependencies { | |
implementation("com.benasher44:uuid:0.3.0") | |
implementation("com.apollographql.apollo3:apollo-runtime:3.0.0-dev13") | |
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core"){ | |
version { | |
strictly("1.5.0") | |
} | |
} | |
api("co.touchlab:kermit:0.1.9") | |
} | |
} | |
val commonTest by getting { | |
dependencies { | |
implementation(kotlin("test-common")) | |
implementation(kotlin("test-annotations-common")) | |
} | |
} | |
val androidMain by getting { | |
dependencies { | |
} | |
} | |
val androidTest by getting { | |
dependencies { | |
implementation(kotlin("test-junit")) | |
implementation("junit:junit:4.13.2") | |
} | |
} | |
val iosMain by getting | |
val iosTest by getting | |
} | |
} | |
kotlin { | |
targets.withType<KotlinNativeTarget> { | |
compilations["main"].kotlinOptions.freeCompilerArgs += "-Xexport-kdoc" | |
} | |
} | |
android { | |
compileSdkVersion(30) | |
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") | |
defaultConfig { | |
minSdk = 26 | |
targetSdk = 30 | |
} | |
} | |
//used to create XCFramework contains arm64 and x64 | |
task("createFullXCFramework") { | |
group = "multiplatform-swift-package" | |
doLast { | |
val rootProjectPath = rootProject.projectDir.absolutePath | |
val swiftPackageDir = File(rootProjectPath, "shared/swiftpackage") | |
swiftPackageDir.deleteRecursively()//clean origin created xcframework | |
Runtime.getRuntime().exec("$rootProjectPath/gradlew createXCFramework -PfulliOS").run { | |
inputStream.reader().forEachLine { | |
println(it) | |
} | |
errorStream.reader().forEachLine { | |
println(it) | |
} | |
} | |
} | |
} | |
//used to create XCFramework contains arm64 and x64 | |
task("createFullSwiftPackage") { | |
group = "multiplatform-swift-package" | |
doLast { | |
val rootProjectPath = rootProject.projectDir.absolutePath | |
val swiftPackageDir = File(rootProjectPath, "shared/swiftpackage") | |
swiftPackageDir.deleteRecursively()//clean origin created xcframework | |
Runtime.getRuntime().exec("$rootProjectPath/gradlew createSwiftPackage -PfulliOS").run { | |
inputStream.reader().forEachLine { | |
println(it) | |
} | |
errorStream.reader().forEachLine { | |
println(it) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment