import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework import java.util.Properties import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.BOOLEAN import java.time.Instant plugins { alias(libs.plugins.android.kotlin.multiplatform.library) alias(libs.plugins.android.lint) // Compose Compiler plugin (Kotlin ≥2.0): krävs för Compose Multiplatform i :shared. // Versionen kommer från libs.versions.toml (plugins.kotlin-compose -> kotlin). alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotlin.serialization) // JetBrains Compose Multiplatform för UI i :shared/commonMain. // Viktigt: detta är *inte* AndroidX Compose BOM. Vi använder compose.*-aliasen // (org.jetbrains.compose) vilket gör att :shared förblir plattformsneutral. id("org.jetbrains.compose") version "1.9.0" id("com.codingfeline.buildkonfig") version "0.17.1" kotlin("native.cocoapods") id("app.cash.sqldelight") version "2.1.0" } kotlin { // Target declarations - add or remove as needed below. These define // which platforms this KMP module supports. // See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets androidLibrary { namespace = "app.klottr.shared" compileSdk = 36 minSdk = 26 withHostTestBuilder { } withDeviceTestBuilder { sourceSetTreeName = "test" }.configure { instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } } // For iOS targets, this is also where you should // configure native binary output. For more information, see: // https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks // A step-by-step guide on how to include this library in an XCode // project can be found here: // https://developer.android.com/kotlin/multiplatform/migrate val xcfName = "shared" val xcf = XCFramework() iosX64 { binaries.framework { baseName = xcfName isStatic = true xcf.add(this) } } iosArm64 { binaries.framework { baseName = xcfName isStatic = true xcf.add(this) } } iosSimulatorArm64 { binaries.framework { baseName = xcfName isStatic = true xcf.add(this) } } // Cocoapods is used for 3rd party library dependencies in iOS cocoapods { version = "1.0.0" // Out version of the podspec ios.deploymentTarget = "14.0" framework { baseName = xcfName isStatic = true } // This generates the cinterop => `platform.GoogleMaps.*` pod("GoogleMaps") // keep version unspecified to track latest podspec { // To support clang modules extraOpts += listOf("-compiler-option", "-fmodules") } } // Source set declarations. // Declaring a target automatically creates a source set with the same name. By default, the // Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is // common to share sources between related targets. // See: https://kotlinlang.org/docs/multiplatform-hierarchy.html sourceSets { commonMain { dependencies { implementation(libs.kotlin.stdlib) implementation(libs.ktor.client.core) // Add KMP dependencies here implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.serialization.kotlinx.json) // JSON-runtime explicit (bra för versionssäkring) implementation(libs.kotlinx.serialization.json) implementation(libs.ktor.client.logging) // CMP-runtime & foundation. Paketnamnen i koden är androidx.compose.*, // men artefakterna kommer från JetBrains Compose via compose.*-aliasen. // Lämna AndroidX Compose BOM/runtimes utanför :shared. implementation(compose.runtime) implementation(compose.foundation) implementation(compose.material) implementation(compose.material3) // Material Icons (Icons.Filled.*, Icons.Outlined.*) implementation(compose.materialIconsExtended) implementation(compose.components.resources) // Coil 3 (KMP) — image loading + caching for Compose Multiplatform implementation("io.coil-kt.coil3:coil-compose:3.3.0") // Use Ktor-based multiplatform networking backend for Coil implementation("io.coil-kt.coil3:coil-network-ktor3:3.3.0") // SQLDelight Coroutines Extensions: // Gör att queries (t.ex. notesQueries.all()) kan exponeras som Flow. // Flow används ihop med Compose för att automatiskt uppdatera UI när DB-data ändras. implementation("app.cash.sqldelight:coroutines-extensions:2.1.0") // Kotlinx coroutines-core (krävs för Flow + SQLDelight coroutines-extensions) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0") // för Compose i :shared (Android-del) // OBS: Dessa AndroidX Compose-rader ska förbli utkommenterade i :shared. // :shared använder JetBrains Compose (org.jetbrains.compose) för CMP. //implementation(project.dependencies.platform("androidx.compose:compose-bom:${libs.versions.composeBom.get()}")) //implementation(libs.androidx.ui) //implementation(libs.androidx.material3) } // resources.srcDirs( // "src/commonMain/composeResources", // "src/commonMain/resources" // ) } commonTest { dependencies { implementation(libs.kotlin.test) } } androidMain { dependencies { // Add Android-specific dependencies here. Note that this source set depends on // commonMain by default and will correctly pull the Android artifacts of any KMP // dependencies declared in commonMain. implementation(libs.ktor.client.okhttp) implementation("com.google.android.gms:play-services-location:21.3.0") // FusedLocation implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.9.0") // await() på Tasks implementation("com.google.maps.android:maps-compose:6.10.0") // Sep 9, 2025 // Google Sign-In implementation("com.google.android.gms:play-services-auth:21.4.0") implementation(libs.androidx.work.runtime.ktx) // rememberLauncherForActivityResult() implementation("androidx.activity:activity-compose:1.11.0") // PickVisualMediaRequest + ActivityResultContracts.* implementation("androidx.activity:activity:1.11.0") // SQLDelight Android-driver implementation("app.cash.sqldelight:android-driver:2.1.0") // SQLDelight coroutine-extensions (JVM/Android) implementation("app.cash.sqldelight:coroutines-extensions:2.1.0") } } getByName("androidDeviceTest") { dependencies { implementation(libs.androidx.runner) implementation(libs.androidx.core) implementation(libs.androidx.junit) } } iosMain { dependencies { // Add iOS-specific dependencies here. This a source set created by Kotlin Gradle // Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as // part of KMP’s default source set hierarchy. Note that this source set depends // on common by default and will correctly pull the iOS artifacts of any // KMP dependencies declared in commonMain. implementation(libs.ktor.client.darwin) } } } } // ------------------- BuildKonfig (shared constants) ------------------- // Read local.properties (or override via -PKEY=VALUE) val localProps = Properties().apply { val f = rootProject.file("local.properties") if (f.exists()) f.inputStream().use { load(it) } } fun prop(name: String): String? = providers.gradleProperty(name).orNull ?: localProps.getProperty(name) fun propOr(name: String, default: String) = prop(name) ?: default val buildTimeUtc: String = Instant.now().toString() // Infer build type from tasks (Debug/Release), but allow override via -PBUILD_TYPE=... val inferredBuildType: String = providers.gradleProperty("BUILD_TYPE").orNull ?: if (gradle.startParameter.taskNames.any { it.contains("release", ignoreCase = true) }) "release" else "debug" buildkonfig { packageName = "app.klottr" defaultConfigs { buildConfigField(STRING, "BUILD_TYPE", inferredBuildType ) buildConfigField(STRING, "APP_NAME", "Klottr") buildConfigField(STRING, "BUILD_TIME_UTC", buildTimeUtc) buildConfigField(STRING, "SERVER_API_BASE_URL", propOr("SERVER_API_BASE_URL", "")) buildConfigField(STRING, "SERVER_API_KEY", propOr("SERVER_API_KEY", "")) buildConfigField(STRING, "WEB_CLIENT_ID", propOr("WEB_CLIENT_ID", "")) buildConfigField(STRING, "DM_API_KEY", propOr("DM_API_KEY", "")) buildConfigField(STRING, "DM_OWNERS", propOr("DM_OWNERS", "")) buildConfigField(BOOLEAN, "KLLOG_DEBUG", propOr("KLLOG_DEBUG", "false")) buildConfigField(BOOLEAN, "KLLOG_HTTP_DEBUG", propOr("KLLOG_HTTP_DEBUG", "false")) } } sqldelight { databases { create("KlottrDatabase") { packageName.set("app.klottr.db") } } }