Hi everyone, I'm experiencing significantly long ...
# multiplatform
m
Hi everyone, I'm experiencing significantly long build times with my
KMM
project. While building a native Android project typically takes
10-30 seconds
, building the KMM project can take up to
10 minutes
. I'm looking for ways to speed up this process. Here are the details of my current setup: • Gradle version: 8.7 • agp : 8.2.2 • Kotlin version: 2.0.0 • JavaVersion.VERSION_11 I've already tried the following optimizations: • Enabled the Gradle Daemon. • Enabled parallel project execution. • Configured incremental compilation for Kotlin. • Using Gradle build cache. Does anyone have any additional suggestions or best practices for reducing build times in KMM projects? Any configurations, tools, or techniques that have worked for you would be greatly appreciated! Thank you!
b
what targets do you have on your KMP modules?
e
Gradle configuration cache enables parallel execution of tasks within a project
m
@Bruno Medeiros
Copy code
kotlin {
    androidTarget {
        @OptIn(ExperimentalKotlinGradlePluginApi::class)
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_11)
        }
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "ComposeApp"
            isStatic = true
        }
    }

    sourceSets {
        androidMain.dependencies {
            implementation(libs.androidx.compose.ui.tooling.preview)
            implementation(libs.androidx.activity.compose)
            implementation(libs.ktor.client.okhttp)
        }
        iosMain.dependencies {
            implementation(libs.ktor.client.darwin)
        }
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)

            implementation(libs.ktor.client.core)
            implementation(libs.ktor.client.content.negotiation)
            implementation(libs.ktor.serialization.kotlinx.json)

            implementation(libs.kamel)
            implementation(libs.koin.core)
            implementation(libs.voyager.navigator)
            implementation(libs.voyager.koin)
        }
    }
}
e
yeah native compilation and especially linking is currently much slower
m
@ephemient So, at this stage, it's typical for the build to take that long time. Right?
kotlin.incremental.native=true
Would probably help a bunch for native builds after the first build
m
Thank you @Luca. I also realized that I shouldn't build the project every time. It's interesting.
👍 2
l
still experimental so might cause strange issues but you can always toggle it