Hi everyone, has anyone solved the issue where the...
# multiplatform
v
Hi everyone, has anyone solved the issue where the KMP iOS release build is taking more than 30 minutes? Here is the configuration I am currently using.
gradle.properties
Copy code
# Kotlin
kotlin.code.style=official
kotlin.daemon.jvmargs=-Xmx6144M -XX:MaxMetaspaceSize=512m -XX:+UseG1GC

# Kotlin/Native compiler runs its own JVM process — separate from the Kotlin daemon
kotlin.native.jvmArgs=-Xmx12288M -XX:MaxMetaspaceSize=1g -XX:+UseG1GC

# Gradle
org.gradle.jvmargs=-Xmx8g -XX:MaxMetaspaceSize=1g
org.gradle.configuration-cache=true
org.gradle.caching=true

# Android
android.nonTransitiveRClass=true
android.useAndroidX=true
build.gradle.kts
Copy code
listOf(
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "ComposeApp"
        isStatic = true

        // Disable the DevirtualizationAnalysis phase which OOMs on large projects.
        // This skips an interprocedural optimization pass — the binary is slightly
        // larger but functionally identical. Dead code elimination still runs.
        freeCompilerArgs += listOf(
            "-Xdisable-phases=DevirtualizationAnalysis",
            "-Xadd-light-debug=disable",
        )
    }
}
If anyone has optimized the KMP iOS release build time, please share the best approach or configuration.
v
Thank you 😊
a
Have you seen and tried the documentation on the topic? https://kotlinlang.org/docs/native-improving-compilation-time.html
v
still first time build took 40 min.
Copy code
listOf(
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "ComposeApp"
            isStatic = true
            // KDoc export (on by default since 2.2.20) bloats ObjC header generation for no benefit
            // in an app framework — Xcode autocomplete never reads it meaningfully.
            @OptIn(ExperimentalKotlinGradlePluginApi::class)
            exportKdoc.set(false)
            // DevirtualizationAnalysis OOMs on large projects; skipping is safe — DCE still runs.
            // EscapeAnalysis is an expensive stack-allocation pass; its gain rarely justifies the
            // compile time cost on a large app codebase.
            // light-debug=disable skips generation of debug metadata in release binaries.
            freeCompilerArgs += listOf(
                "-Xdisable-phases=DevirtualizationAnalysis",
                "-Xdisable-phases=EscapeAnalysis",
                "-Xadd-light-debug=disable",
            )
        }
    }
and
Copy code
#Kotlin
kotlin.code.style=official
kotlin.daemon.jvmargs=-Xmx6144M -XX:MaxMetaspaceSize=512m -XX:+UseG1GC
# Kotlin/Native compiler runs its own JVM process â separate from the Kotlin daemon
kotlin.native.jvmArgs=-Xmx12288M -XX:MaxMetaspaceSize=1g -XX:+UseG1GC

# Incremental K/N klib compilation â avoids recompiling unchanged source sets between builds
kotlin.incremental.native=true

# Switch LLVM from -O2 to -Oz for release binaries: smaller binary AND faster LLVM phase
# (Experimental in Kotlin 2.2.20+; primary driver of 30-40 min release build times)
kotlin.native.binary.smallBinary=true

#Gradle
org.gradle.jvmargs=-Xmx8g -XX:MaxMetaspaceSize=1g
org.gradle.configuration-cache=true
org.gradle.caching=true
# Allow independent tasks (e.g. kspIosArm64, kspIosSimulatorArm64) to run concurrently
org.gradle.parallel=true

#Android
android.nonTransitiveRClass=true
android.useAndroidX=true
this medium blog helped me now build time is 10 min