Skip to content

Commit 20c5188

Browse files
committed
Add KMP shared module
1 parent 280a52e commit 20c5188

File tree

9 files changed

+133
-10
lines changed

9 files changed

+133
-10
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ plugins {
1010
alias(libs.plugins.kotlin.parcelize) apply false
1111
alias(libs.plugins.compose.compiler) apply false
1212
alias(libs.plugins.kotlin.serialization) apply false
13+
alias(libs.plugins.kotlin.multiplatform) apply false
14+
alias(libs.plugins.android.kotlin.multiplatform.library) apply false
15+
alias(libs.plugins.android.lint) apply false
1316
}
1417

1518
apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ play-services-wearable = { module = "com.google.android.gms:play-services-wearab
189189
validator-push = { module = "com.google.android.wearable.watchface.validator:validator-push", version.ref = "validatorPush" }
190190
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
191191
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }
192+
jetbrains-kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
193+
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
192194

193195
[plugins]
194196
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
@@ -201,3 +203,6 @@ kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref =
201203
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
202204
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
203205
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }
206+
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
207+
android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "androidGradlePlugin" }
208+
android-lint = { id = "com.android.lint", version.ref = "androidGradlePlugin" }

kmp/kmp-shared/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

kmp/kmp-shared/build.gradle.kts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.multiplatform)
3+
alias(libs.plugins.android.kotlin.multiplatform.library)
4+
alias(libs.plugins.android.lint)
5+
}
6+
7+
kotlin {
8+
9+
// Target declarations - add or remove as needed below. These define
10+
// which platforms this KMP module supports.
11+
// See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets
12+
androidLibrary {
13+
namespace = "com.example.kmp.kmp_shared"
14+
compileSdk = 36
15+
minSdk = 24
16+
17+
withHostTestBuilder {
18+
}
19+
20+
withDeviceTestBuilder {
21+
sourceSetTreeName = "test"
22+
}.configure {
23+
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
24+
}
25+
}
26+
27+
// For iOS targets, this is also where you should
28+
// configure native binary output. For more information, see:
29+
// https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks
30+
31+
// A step-by-step guide on how to include this library in an XCode
32+
// project can be found here:
33+
// https://developer.android.com/kotlin/multiplatform/migrate
34+
val xcfName = "kmp-sharedKit"
35+
36+
iosX64 {
37+
binaries.framework {
38+
baseName = xcfName
39+
}
40+
}
41+
42+
iosArm64 {
43+
binaries.framework {
44+
baseName = xcfName
45+
}
46+
}
47+
48+
iosSimulatorArm64 {
49+
binaries.framework {
50+
baseName = xcfName
51+
}
52+
}
53+
54+
// Source set declarations.
55+
// Declaring a target automatically creates a source set with the same name. By default, the
56+
// Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is
57+
// common to share sources between related targets.
58+
// See: https://kotlinlang.org/docs/multiplatform-hierarchy.html
59+
sourceSets {
60+
commonMain {
61+
dependencies {
62+
implementation(libs.jetbrains.kotlin.stdlib)
63+
// Add KMP dependencies here
64+
}
65+
}
66+
67+
commonTest {
68+
dependencies {
69+
implementation(libs.kotlin.test)
70+
}
71+
}
72+
73+
androidMain {
74+
dependencies {
75+
// Add Android-specific dependencies here. Note that this source set depends on
76+
// commonMain by default and will correctly pull the Android artifacts of any KMP
77+
// dependencies declared in commonMain.
78+
}
79+
}
80+
81+
getByName("androidDeviceTest") {
82+
dependencies {
83+
implementation(libs.androidx.test.runner)
84+
implementation(libs.androidx.test.core)
85+
implementation(libs.androidx.test.ext.junit)
86+
}
87+
}
88+
89+
iosMain {
90+
dependencies {
91+
// Add iOS-specific dependencies here. This a source set created by Kotlin Gradle
92+
// Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as
93+
// part of KMP’s default source set hierarchy. Note that this source set depends
94+
// on common by default and will correctly pull the iOS artifacts of any
95+
// KMP dependencies declared in commonMain.
96+
}
97+
}
98+
}
99+
100+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.example.kmp.kmp_shared
2+
3+
actual fun platform() = "Android"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.example.kmp.kmp_shared
2+
3+
expect fun platform(): String
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.example.kmp.kmp_shared
2+
3+
actual fun platform() = "iOS"

settings.gradle.kts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val snapshotVersion : String? = System.getenv("COMPOSE_SNAPSHOT_ID")
1+
val snapshotVersion: String? = System.getenv("COMPOSE_SNAPSHOT_ID")
22

33
pluginManagement {
44
repositories {
@@ -30,13 +30,14 @@ dependencyResolutionManagement {
3030
rootProject.name = "snippets"
3131
include(
3232
":bluetoothle",
33-
":compose:recomposehighlighter",
34-
":kotlin",
35-
":compose:snippets",
36-
":wear",
37-
":views",
38-
":misc",
39-
":identity:credentialmanager",
40-
":xr",
41-
":watchfacepush:validator"
33+
":compose:recomposehighlighter",
34+
":kotlin",
35+
":compose:snippets",
36+
":wear",
37+
":views",
38+
":misc",
39+
":identity:credentialmanager",
40+
":xr",
41+
":watchfacepush:validator",
42+
":kmp:kmp-shared",
4243
)

0 commit comments

Comments
 (0)