Skip to content

Instantly share code, notes, and snippets.

@marenovakovic
Last active February 6, 2023 08:00
Show Gist options
  • Save marenovakovic/e6c3b051922cdcc167bfe07dd4793872 to your computer and use it in GitHub Desktop.
Save marenovakovic/e6c3b051922cdcc167bfe07dd4793872 to your computer and use it in GitHub Desktop.
Compose iOS gradle setup
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.compose.experimental.dsl.IOSDevices
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose") version "1.3.0-rc01"
}
version = "1.0"
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
kotlin {
iosX64("uikitX64") {
binaries {
executable {
entryPoint = "main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
}
}
iosArm64("uikitArm64") {
binaries {
executable {
entryPoint = "main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
project(":shared") // optional. if you have KMM project
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.runtime)
}
}
val commonTest by getting {
dependencies {}
}
val nativeMain by creating {
dependsOn(commonMain)
}
val uikitMain by creating {
dependsOn(nativeMain)
}
val uikitX64Main by getting {
dependsOn(uikitMain)
}
val uikitArm64Main by getting {
dependsOn(uikitMain)
}
}
}
compose.experimental {
uikit.application {
bundleIdPrefix = "com.yourpackage"
projectName = "yourProjectName"
deployConfigurations {
simulator("IPhone13Pro") {
//Usage: ./gradlew iosDeployIPhone13ProDebug
device = IOSDevices.IPHONE_13_PRO
}
simulator("IPad") {
//Usage: ./gradlew iosDeployIPadDebug
device = IOSDevices.IPAD_MINI_6th_Gen
}
connectedDevice("Device") {
//First need specify your teamId here, or in local.properties (compose.ios.teamId=***)
teamId="yourReamId"
//Usage: ./gradlew iosDeployDeviceRelease
}
}
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
kotlin {
targets.withType<KotlinNativeTarget> {
binaries.all {
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}
// TODO: remove when https://youtrack.jetbrains.com/issue/KT-50778 fixed
project.tasks.withType(org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile::class.java).configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-Xir-dce-runtime-diagnostic=log"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment