Hello. I have multiple modules in my KMP project w...
# multiplatform
d
Hello. I have multiple modules in my KMP project with each module have its build.gradle.kts file which is almost duplicate. I wanted to extract out the common gradle code to common.gradle.kts as below:
Copy code
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

kotlin {
    android()

    val xcf = XCFramework()
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = moduleName // Use the moduleName parameter here
            xcf.add(this)
            isStatic = true
        }
    }
}

android {
    namespace = androidNamespace // Use the androidNamespace parameter here
    compileSdk = 34

    defaultConfig {
        minSdk = 21
        consumerProguardFiles("<http://consumer-rules.pro|consumer-rules.pro>")
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "<http://proguard-rules.pro|proguard-rules.pro>"
            )
        }
    }
}
But on gradle sync giving multiple errors and all related to XCFramework, iOS etc which is there in above common gradle file. Is anyone successfully creatde any common.gradle.kts?
p
Can you post the errors? I have only used the Xcframework in the umbrella module most known as 'composeApp' these days,
shared
back in time. But I haven't heard is a limitation to create an xcframework out of any module.
Perhaps nesting modules that produce xcframework is a limitation but I am not sure either. Hopefully someone shed some light.
a
What I did was using the catalog files to have the different text values and then just use vars
that way you can copy/paste the gradle scripts and apply the different values using the vars, and only change the catalog name
you can use as many catalog files as you want, just don't go with the default provided, create your own catalogs
m
Composite builds are where it's at, imo.