Skip to content

Commit 5ac9c2c

Browse files
authored
Merge pull request #3 from pahill/main
Update Get Started with KMP tutorial for 03/01/2024 changes
2 parents adb6021 + 0afbb94 commit 5ac9c2c

File tree

102 files changed

+3449
-884
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3449
-884
lines changed

.gitignore

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

step2/androidApp/build.gradle.kts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
plugins {
2-
id("com.android.application")
3-
kotlin("android")
2+
alias(libs.plugins.androidApplication)
3+
alias(libs.plugins.kotlinAndroid)
44
}
55

66
android {
7-
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox"
7+
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android"
88
compileSdk = 34
99
defaultConfig {
10-
applicationId = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox"
11-
minSdk = 26
10+
applicationId = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android"
11+
minSdk = 24
1212
targetSdk = 34
1313
versionCode = 1
1414
versionName = "1.0"
@@ -17,7 +17,7 @@ android {
1717
compose = true
1818
}
1919
composeOptions {
20-
kotlinCompilerExtensionVersion = "1.5.4-dev-k1.9.20-Beta2-ac5f960bdaf"
20+
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
2121
}
2222
packaging {
2323
resources {
@@ -30,20 +30,19 @@ android {
3030
}
3131
}
3232
compileOptions {
33-
sourceCompatibility = JavaVersion.VERSION_17
34-
targetCompatibility = JavaVersion.VERSION_17
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
3535
}
3636
kotlinOptions {
37-
jvmTarget = "17"
37+
jvmTarget = "1.8"
3838
}
3939
}
4040

4141
dependencies {
42-
implementation(project(":shared"))
43-
implementation("androidx.compose.ui:ui:1.5.3")
44-
implementation("androidx.compose.ui:ui-tooling:1.5.3")
45-
implementation("androidx.compose.ui:ui-tooling-preview:1.5.3")
46-
implementation("androidx.compose.foundation:foundation:1.5.3")
47-
implementation("androidx.compose.material:material:1.5.3")
48-
implementation("androidx.activity:activity-compose:1.8.0")
42+
implementation(projects.shared)
43+
implementation(libs.compose.ui)
44+
implementation(libs.compose.ui.tooling.preview)
45+
implementation(libs.compose.material3)
46+
implementation(libs.androidx.activity.compose)
47+
debugImplementation(libs.compose.ui.tooling)
4948
}

step2/androidApp/src/main/java/com/jetbrains/simplelogin/kotlinmultiplatformsandbox/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox
1+
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android
22

33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
66
import androidx.compose.foundation.layout.fillMaxSize
7-
import androidx.compose.material.*
7+
import androidx.compose.material3.*
88
import androidx.compose.runtime.Composable
99
import androidx.compose.ui.Modifier
1010
import androidx.compose.ui.tooling.preview.Preview
@@ -17,7 +17,7 @@ class MainActivity : ComponentActivity() {
1717
MyApplicationTheme {
1818
Surface(
1919
modifier = Modifier.fillMaxSize(),
20-
color = MaterialTheme.colors.background
20+
color = MaterialTheme.colorScheme.background
2121
) {
2222
GreetingView(Greeting().greet())
2323
}

step2/androidApp/src/main/java/com/jetbrains/simplelogin/kotlinmultiplatformsandbox/MyApplicationTheme.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox
1+
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android
22

33
import androidx.compose.foundation.isSystemInDarkTheme
44
import androidx.compose.foundation.shape.RoundedCornerShape
5-
import androidx.compose.material.MaterialTheme
6-
import androidx.compose.material.Shapes
7-
import androidx.compose.material.Typography
8-
import androidx.compose.material.darkColors
9-
import androidx.compose.material.lightColors
5+
import androidx.compose.material3.MaterialTheme
6+
import androidx.compose.material3.Shapes
7+
import androidx.compose.material3.Typography
8+
import androidx.compose.material3.darkColorScheme
9+
import androidx.compose.material3.lightColorScheme
1010
import androidx.compose.runtime.Composable
1111
import androidx.compose.ui.graphics.Color
1212
import androidx.compose.ui.text.TextStyle
@@ -21,20 +21,20 @@ fun MyApplicationTheme(
2121
content: @Composable () -> Unit
2222
) {
2323
val colors = if (darkTheme) {
24-
darkColors(
24+
darkColorScheme(
2525
primary = Color(0xFFBB86FC),
26-
primaryVariant = Color(0xFF3700B3),
27-
secondary = Color(0xFF03DAC5)
26+
secondary = Color(0xFF03DAC5),
27+
tertiary = Color(0xFF3700B3)
2828
)
2929
} else {
30-
lightColors(
30+
lightColorScheme(
3131
primary = Color(0xFF6200EE),
32-
primaryVariant = Color(0xFF3700B3),
33-
secondary = Color(0xFF03DAC5)
32+
secondary = Color(0xFF03DAC5),
33+
tertiary = Color(0xFF3700B3)
3434
)
3535
}
3636
val typography = Typography(
37-
body1 = TextStyle(
37+
bodyMedium = TextStyle(
3838
fontFamily = FontFamily.Default,
3939
fontWeight = FontWeight.Normal,
4040
fontSize = 16.sp
@@ -47,7 +47,7 @@ fun MyApplicationTheme(
4747
)
4848

4949
MaterialTheme(
50-
colors = colors,
50+
colorScheme = colors,
5151
typography = typography,
5252
shapes = shapes,
5353
content = content

step2/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
//trick: for the same plugin versions in all sub-modules
3-
id("com.android.application").version("8.1.2").apply(false)
4-
id("com.android.library").version("8.1.2").apply(false)
5-
kotlin("android").version("1.9.20-Beta2").apply(false)
6-
kotlin("multiplatform").version("1.9.20-Beta2").apply(false)
3+
alias(libs.plugins.androidApplication).apply(false)
4+
alias(libs.plugins.androidLibrary).apply(false)
5+
alias(libs.plugins.kotlinAndroid).apply(false)
6+
alias(libs.plugins.kotlinMultiplatform).apply(false)
77
}

step2/gradle/libs.versions.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[versions]
2+
agp = "8.2.0-rc03"
3+
kotlin = "1.9.20"
4+
compose = "1.5.4"
5+
compose-compiler = "1.5.4"
6+
compose-material3 = "1.1.2"
7+
androidx-activityCompose = "1.8.0"
8+
9+
[libraries]
10+
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
11+
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
12+
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
13+
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
14+
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
15+
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
16+
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }
17+
18+
[plugins]
19+
androidApplication = { id = "com.android.application", version.ref = "agp" }
20+
androidLibrary = { id = "com.android.library", version.ref = "agp" }
21+
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
22+
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
23+
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }

step2/settings.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
12
pluginManagement {
23
repositories {
34
google()
@@ -10,10 +11,9 @@ dependencyResolutionManagement {
1011
repositories {
1112
google()
1213
mavenCentral()
13-
maven("https://androidx.dev/storage/compose-compiler/repository/")
1414
}
1515
}
1616

17-
rootProject.name = "KotlinMultiplatformSandbox"
17+
rootProject.name = "Kotlin_Multiplatform_Sandbox"
1818
include(":androidApp")
1919
include(":shared")

step2/shared/build.gradle.kts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
kotlin("multiplatform")
3-
id("com.android.library")
2+
alias(libs.plugins.kotlinMultiplatform)
3+
alias(libs.plugins.androidLibrary)
44
}
55

66
kotlin {
@@ -11,27 +11,24 @@ kotlin {
1111
}
1212
}
1313
}
14-
14+
1515
listOf(
1616
iosX64(),
1717
iosArm64(),
1818
iosSimulatorArm64()
1919
).forEach {
2020
it.binaries.framework {
2121
baseName = "shared"
22+
isStatic = true
2223
}
2324
}
2425

2526
sourceSets {
26-
commonMain {
27-
dependencies {
28-
//put your multiplatform dependencies here
29-
}
27+
commonMain.dependencies {
28+
//put your multiplatform dependencies here
3029
}
31-
commonTest {
32-
dependencies {
33-
implementation(kotlin("test"))
34-
}
30+
commonTest.dependencies {
31+
implementation(libs.kotlin.test)
3532
}
3633
}
3734
}
@@ -40,6 +37,6 @@ android {
4037
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox"
4138
compileSdk = 34
4239
defaultConfig {
43-
minSdk = 26
40+
minSdk = 24
4441
}
45-
}
42+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.jetbrains.simplelogin.kotlinmultiplatformsandbox
22

3+
import kotlin.random.Random
34
class Greeting {
45
private val platform: Platform = getPlatform()
56

67
fun greet(): String {
7-
return "Guess what it is! > ${platform.name.reversed()}!"
8+
val firstWord = if (Random.nextBoolean()) "Hi!" else "Hello!"
9+
10+
return "$firstWord Guess what this is! > ${platform.name.reversed()}!"
811
}
912
}

step3/androidApp/build.gradle.kts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
plugins {
2-
id("com.android.application")
3-
kotlin("android")
2+
alias(libs.plugins.androidApplication)
3+
alias(libs.plugins.kotlinAndroid)
44
}
55

66
android {
7-
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox"
7+
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android"
88
compileSdk = 34
99
defaultConfig {
10-
applicationId = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox"
11-
minSdk = 26
10+
applicationId = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox.android"
11+
minSdk = 24
1212
targetSdk = 34
1313
versionCode = 1
1414
versionName = "1.0"
@@ -17,7 +17,7 @@ android {
1717
compose = true
1818
}
1919
composeOptions {
20-
kotlinCompilerExtensionVersion = "1.5.4-dev-k1.9.20-Beta2-ac5f960bdaf"
20+
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
2121
}
2222
packaging {
2323
resources {
@@ -30,20 +30,19 @@ android {
3030
}
3131
}
3232
compileOptions {
33-
sourceCompatibility = JavaVersion.VERSION_17
34-
targetCompatibility = JavaVersion.VERSION_17
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
3535
}
3636
kotlinOptions {
37-
jvmTarget = "17"
37+
jvmTarget = "1.8"
3838
}
3939
}
4040

4141
dependencies {
42-
implementation(project(":shared"))
43-
implementation("androidx.compose.ui:ui:1.5.3")
44-
implementation("androidx.compose.ui:ui-tooling:1.5.3")
45-
implementation("androidx.compose.ui:ui-tooling-preview:1.5.3")
46-
implementation("androidx.compose.foundation:foundation:1.5.3")
47-
implementation("androidx.compose.material:material:1.5.3")
48-
implementation("androidx.activity:activity-compose:1.8.0")
42+
implementation(projects.shared)
43+
implementation(libs.compose.ui)
44+
implementation(libs.compose.ui.tooling.preview)
45+
implementation(libs.compose.material3)
46+
implementation(libs.androidx.activity.compose)
47+
debugImplementation(libs.compose.ui.tooling)
4948
}

0 commit comments

Comments
 (0)