To add a module to a multi-module KMP or CMP, follow these steps.
Note: Update gradle files according to your requirements.
1- Add a folder in the directory e.g “auth”
2-Update Settings.gradle.kts at the end of bottominclude(“feature:auth”)
Press “Sync Now”
3-Add “build.gradle.kts” file in the created module directory
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.jetbrains.kotlin.serialization)
}
kotlin{
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "FeatureAuth"
isStatic = true
}
}
sourceSets{
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
//Personal Modules
api(projects.core.network)
api(projects.core.domain)
api(projects.core.common)
//3rd Party Libs
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.koin.compose.viewmodel)
implementation(libs.bundles.ktor)
implementation(libs.bundles.coil)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
implementation(kotlin("test-annotations-common"))
implementation(libs.assertk)
implementation(libs.ktor.client.mock)
}
}
}
android{
namespace = "com.example.demo.feature.auth"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
dependencies {
debugImplementation(libs.androidx.ui.tooling)
}
Code language: JavaScript (javascript)
Update baseName = “NewName”
Update namespace = “”
4-Update build.gradle.kts
commonMain.dependencies {
//Personal Modules
implementation(projects.feature.auth)
}
Code language: JavaScript (javascript)
5- add a new directory in a created module like the following for “commonMain“
src/commonMain/kotlin
5-A. You can also add for androidMain and iOSMain as well inside src directory
6- Add another directory with something like the following
com.example.demo.feature.auth