Skip to content

Commit f8b7286

Browse files
committed
Step 3
1 parent 558884b commit f8b7286

File tree

12 files changed

+105
-85
lines changed

12 files changed

+105
-85
lines changed

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
}
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
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
6+
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.PaddingValues
68
import androidx.compose.foundation.layout.fillMaxSize
7-
import androidx.compose.material.*
9+
import androidx.compose.foundation.lazy.LazyColumn
10+
import androidx.compose.foundation.lazy.items
11+
import androidx.compose.material3.*
812
import androidx.compose.runtime.Composable
913
import androidx.compose.ui.Modifier
1014
import androidx.compose.ui.tooling.preview.Preview
15+
import androidx.compose.ui.unit.dp
1116
import com.jetbrains.simplelogin.kotlinmultiplatformsandbox.Greeting
1217

1318
class MainActivity : ComponentActivity() {
@@ -17,7 +22,7 @@ class MainActivity : ComponentActivity() {
1722
MyApplicationTheme {
1823
Surface(
1924
modifier = Modifier.fillMaxSize(),
20-
color = MaterialTheme.colors.background
25+
color = MaterialTheme.colorScheme.background
2126
) {
2227
GreetingView(Greeting().greet())
2328
}
@@ -27,14 +32,22 @@ class MainActivity : ComponentActivity() {
2732
}
2833

2934
@Composable
30-
fun GreetingView(text: String) {
31-
Text(text = text)
35+
fun GreetingView(phrases: List<String>) {
36+
LazyColumn(
37+
contentPadding = PaddingValues(20.dp),
38+
verticalArrangement = Arrangement.spacedBy(8.dp),
39+
) {
40+
items(phrases) { phrase ->
41+
Text(phrase)
42+
Divider()
43+
}
44+
}
3245
}
3346

3447
@Preview
3548
@Composable
3649
fun DefaultPreview() {
3750
MyApplicationTheme {
38-
GreetingView("Hello, Android!")
51+
GreetingView(listOf("Hello, Android!"))
3952
}
40-
}
53+
}

step3/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

step3/build.gradle.kts

Lines changed: 5 additions & 5 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)
7-
}
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)
7+
}

step3/gradle.properties

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ kotlin.code.style=official
88

99
#Android
1010
android.useAndroidX=true
11-
android.nonTransitiveRClass=true
12-
13-
#MPP
14-
kotlin.mpp.enableCInteropCommonization=true
11+
android.nonTransitiveRClass=true

step3/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" }
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Jul 11 12:27:33 SAST 2023
1+
#Tue Dec 12 15:01:59 SAST 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

step3/iosApp/iosApp/ContentView.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import SwiftUI
22
import shared
33

44
struct ContentView: View {
5-
let greet = Greeting().greet()
5+
let phrases = Greeting().greet()
66

7-
var body: some View {
8-
Text(greet)
9-
}
7+
var body: some View {
8+
List(phrases, id: \.self) {
9+
Text($0)
10+
}
11+
}
1012
}
1113

1214
struct ContentView_Previews: PreviewProvider {
1315
static var previews: some View {
1416
ContentView()
1517
}
16-
}
18+
}

step3/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")

step3/shared/build.gradle.kts

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

66
kotlin {
77
androidTarget {
88
compilations.all {
99
kotlinOptions {
10-
jvmTarget = "17"
10+
jvmTarget = "1.8"
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-
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
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,10 +37,6 @@ android {
4037
namespace = "com.jetbrains.simplelogin.kotlinmultiplatformsandbox"
4138
compileSdk = 34
4239
defaultConfig {
43-
minSdk = 26
40+
minSdk = 24
4441
}
45-
compileOptions {
46-
sourceCompatibility = JavaVersion.VERSION_17
47-
targetCompatibility = JavaVersion.VERSION_17
48-
}
49-
}
42+
}

0 commit comments

Comments
 (0)