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
Pablichjenkov
04/12/2024, 9:35 PM
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.
Pablichjenkov
04/12/2024, 9:37 PM
Perhaps nesting modules that produce xcframework is a limitation but I am not sure either. Hopefully someone shed some light.
a
Alejandro Moya
04/12/2024, 9:59 PM
What I did was using the catalog files to have the different text values and then just use vars
Alejandro Moya
04/12/2024, 10:00 PM
that way you can copy/paste the gradle scripts and apply the different values using the vars, and only change the catalog name
Alejandro Moya
04/12/2024, 10:01 PM
you can use as many catalog files as you want, just don't go with the default provided, create your own catalogs