Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions get-started/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ dependencies {
implementation(libs.compose.material3)
implementation(libs.androidx.activity.compose)
debugImplementation(libs.compose.ui.tooling)
implementation(projects.shared)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.example.kmp.shared.platform

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -39,7 +40,7 @@ class MainActivity : ComponentActivity() {
.padding(innerPadding),
contentAlignment = Alignment.Center,
) {
Text("Hello KMP")
Text("Hello ${platform()}")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions get-started/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ plugins {
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.kotlinCompose) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.androidKotlinMultiplatformLibrary) apply false
alias(libs.plugins.androidLint) apply false
alias(libs.plugins.skie) apply false
}

subprojects {
Expand Down
15 changes: 15 additions & 0 deletions get-started/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ kotlinx-coroutines = "1.10.2"
spotless = "7.2.1"
composeBom = "2025.07.00"
ktlint = "1.3.1"
kotlinStdlib = "2.2.0"
kotlinTest = "2.2.0"
runner = "1.5.2"
core = "1.5.0"
junit = "1.1.5"
skie = "0.10.6"


[libraries]
Expand All @@ -39,10 +45,19 @@ compose-material3 = { module = "androidx.compose.material3:material3" }
## Compose BOM End ##

kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlinStdlib" }
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlinTest" }
androidx-runner = { group = "androidx.test", name = "runner", version.ref = "runner" }
androidx-core = { group = "androidx.test", name = "core", version.ref = "core" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junit" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlinxSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlinCompose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
androidKotlinMultiplatformLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
androidLint = { id = "com.android.lint", version.ref = "agp" }
skie = { id = "co.touchlab.skie", version.ref = "skie" }
22 changes: 22 additions & 0 deletions get-started/iosApp/KMPGetStartedCodelab.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 2DCC1BFC2D4100C80017AC11 /* Build configuration list for PBXNativeTarget "KMPGetStartedCodelab" */;
buildPhases = (
04FEC8AD2E978654000D2A5F /* Compile Kotlin Framework */,
2DCC1BEA2D4100C60017AC11 /* Sources */,
2DCC1BEB2D4100C60017AC11 /* Frameworks */,
2DCC1BEC2D4100C60017AC11 /* Resources */,
Expand Down Expand Up @@ -114,6 +115,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
04FEC8AD2E978654000D2A5F /* Compile Kotlin Framework */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Compile Kotlin Framework ";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
2DCC1BEA2D4100C60017AC11 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
3 changes: 2 additions & 1 deletion get-started/iosApp/KMPGetStartedCodelab/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
//

import SwiftUI
import sharedKit

struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, KMP!")
Text("Hello, \(platform())!")
}
.padding()
}
Expand Down
3 changes: 2 additions & 1 deletion get-started/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ dependencyResolutionManagement {
}

rootProject.name = "KmpGetStartedCodelab"
include(":androidApp")
include(":androidApp")
include(":shared")
1 change: 1 addition & 0 deletions get-started/shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
101 changes: 101 additions & 0 deletions get-started/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidKotlinMultiplatformLibrary)
alias(libs.plugins.androidLint)
alias(libs.plugins.skie)
}

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 = "com.example.kmp.shared"
compileSdk = 36
minSdk = 24

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 = "sharedKit"

iosX64 {
binaries.framework {
baseName = xcfName
}
}

iosArm64 {
binaries.framework {
baseName = xcfName
}
}

iosSimulatorArm64 {
binaries.framework {
baseName = xcfName
}
}

// 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)
// Add KMP dependencies here
}
}

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.
}
}

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.
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.kmp.shared

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.kmp.shared.test", appContext.packageName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.kmp.shared

import kotlin.test.Test
import kotlin.test.assertEquals

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
4 changes: 4 additions & 0 deletions get-started/shared/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.kmp.shared

actual fun platform() = "Android"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.kmp.shared

expect fun platform(): String
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.kmp.shared

actual fun platform() = "iOS"
12 changes: 1 addition & 11 deletions migrate-room/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ plugins {
alias(libs.plugins.kotlinCompose)
alias(libs.plugins.kotlinxSerialization)
alias(libs.plugins.ksp)
alias(libs.plugins.room)
alias(libs.plugins.spotless)
alias(libs.plugins.hilt)
}
Expand Down Expand Up @@ -69,9 +68,6 @@ android {
languageVersion = JavaLanguageVersion.of(17)
}
}
ksp {
arg("room.generateKotlin", "true")
}
}

dependencies {
Expand All @@ -92,9 +88,7 @@ dependencies {
implementation(libs.androidx.lifecycle.viewmodel)
debugImplementation(libs.compose.ui.tooling)

ksp(libs.androidx.room.compiler)
// TODO switch this dependency to KMP-ready version
implementation(libs.androidx.room.ktx)
implementation(libs.androidx.room.runtime)

implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
Expand All @@ -111,7 +105,3 @@ dependencies {
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.kotlinx.coroutines.test)
}

room {
schemaDirectory("$projectDir/schemas")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.example.fruitties.kmptutorial.android.di

import android.content.Context
import androidx.room.Room
import com.example.fruitties.kmptutorial.android.database.AppDatabase
import com.example.fruitties.kmptutorial.shared.database.appDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -31,9 +31,9 @@ internal object DatabaseModule {

@Provides
@Singleton
fun providesAppDatabase(@ApplicationContext context: Context): AppDatabase = Room
.databaseBuilder(context, AppDatabase::class.java, "sharedfruits.db")
.build()
fun providesAppDatabase(@ApplicationContext context: Context): AppDatabase {
return appDatabase(context)
}

@Provides
fun providesFruittieDao(appDatabase: AppDatabase) = appDatabase.fruittieDao()
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion migrate-room/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ core = "1.7.0"
skie = "0.10.4"

[libraries]
# TODO add room-runtime and sqlite-bundled dependencies
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidx-room" }
androidx-sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "androidx-sqlite" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
Expand Down
Loading