Skip to content

Commit e5346ea

Browse files
committed
Add a final step example
1 parent 4ce717c commit e5346ea

File tree

57 files changed

+4481
-23
lines changed

Some content is hidden

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

57 files changed

+4481
-23
lines changed

README.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
11
[![Official project](https://jb.gg/badges/official-plastic.svg)](https://github.com/JetBrains#jetbrains-on-github)
22
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
33

4-
### Source code for the ["Get started with Kotlin Multiplatform" tutorial](https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform-getting-started.html)
5-
6-
This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop.
7-
8-
* `/composeApp` is for code that will be shared across your Compose Multiplatform applications.
9-
It contains several subfolders:
10-
- `commonMain` is for code that’s common for all targets.
11-
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
12-
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
13-
`iosMain` would be the right folder for such calls.
14-
15-
* `/iosApp` contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform,
16-
you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.
17-
18-
Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html),
19-
[Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform/#compose-multiplatform),
20-
[Kotlin/Wasm](https://kotl.in/wasm/)
21-
22-
We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack
23-
channel [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web).
24-
If you face any issues, please report them on [YouTrack](https://youtrack.jetbrains.com/newIssue?project=CMP).
25-
26-
You can open the web application by running the `:composeApp:wasmJsBrowserDevelopmentRun` Gradle task.
4+
### Source code for the ["Get started with Compose Multiplatform" tutorial](https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform-getting-started.html)

build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
// this is necessary to avoid the plugins to be loaded multiple times
3+
// in each subproject's classloader
4+
alias(libs.plugins.androidApplication) apply false
5+
alias(libs.plugins.androidLibrary) apply false
6+
alias(libs.plugins.composeHotReload) apply false
7+
alias(libs.plugins.composeMultiplatform) apply false
8+
alias(libs.plugins.composeCompiler) apply false
9+
alias(libs.plugins.kotlinMultiplatform) apply false
10+
}

composeApp/build.gradle.kts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
3+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
4+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
5+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
6+
7+
plugins {
8+
alias(libs.plugins.kotlinMultiplatform)
9+
alias(libs.plugins.androidApplication)
10+
alias(libs.plugins.composeMultiplatform)
11+
alias(libs.plugins.composeCompiler)
12+
alias(libs.plugins.composeHotReload)
13+
}
14+
15+
kotlin {
16+
androidTarget {
17+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
18+
compilerOptions {
19+
jvmTarget.set(JvmTarget.JVM_11)
20+
}
21+
}
22+
23+
listOf(
24+
iosX64(),
25+
iosArm64(),
26+
iosSimulatorArm64()
27+
).forEach { iosTarget ->
28+
iosTarget.binaries.framework {
29+
baseName = "ComposeApp"
30+
isStatic = true
31+
}
32+
}
33+
34+
jvm("desktop")
35+
36+
@OptIn(ExperimentalWasmDsl::class)
37+
wasmJs {
38+
outputModuleName.set("composeApp")
39+
browser {
40+
val rootDirPath = project.rootDir.path
41+
val projectDirPath = project.projectDir.path
42+
commonWebpackConfig {
43+
outputFileName = "composeApp.js"
44+
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
45+
static = (static ?: mutableListOf()).apply {
46+
// Serve sources to debug inside browser
47+
add(rootDirPath)
48+
add(projectDirPath)
49+
}
50+
}
51+
}
52+
}
53+
binaries.executable()
54+
}
55+
56+
sourceSets {
57+
val desktopMain by getting
58+
59+
androidMain.dependencies {
60+
implementation(compose.preview)
61+
implementation(libs.androidx.activity.compose)
62+
}
63+
commonMain.dependencies {
64+
implementation(compose.runtime)
65+
implementation(compose.foundation)
66+
implementation(compose.material3)
67+
implementation(compose.ui)
68+
implementation(compose.components.resources)
69+
implementation(compose.components.uiToolingPreview)
70+
implementation(libs.androidx.lifecycle.viewmodel)
71+
implementation(libs.androidx.lifecycle.runtimeCompose)
72+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.2")
73+
}
74+
commonTest.dependencies {
75+
implementation(libs.kotlin.test)
76+
}
77+
desktopMain.dependencies {
78+
implementation(compose.desktop.currentOs)
79+
implementation(libs.kotlinx.coroutinesSwing)
80+
}
81+
wasmJsMain.dependencies {
82+
implementation(npm("@js-joda/timezone", "2.22.0"))
83+
}
84+
}
85+
}
86+
87+
android {
88+
namespace = "compose.project.demo.composedemo"
89+
compileSdk = libs.versions.android.compileSdk.get().toInt()
90+
91+
defaultConfig {
92+
applicationId = "compose.project.demo.composedemo"
93+
minSdk = libs.versions.android.minSdk.get().toInt()
94+
targetSdk = libs.versions.android.targetSdk.get().toInt()
95+
versionCode = 1
96+
versionName = "1.0"
97+
}
98+
packaging {
99+
resources {
100+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
101+
}
102+
}
103+
buildTypes {
104+
getByName("release") {
105+
isMinifyEnabled = false
106+
}
107+
}
108+
compileOptions {
109+
sourceCompatibility = JavaVersion.VERSION_11
110+
targetCompatibility = JavaVersion.VERSION_11
111+
}
112+
}
113+
114+
dependencies {
115+
debugImplementation(compose.uiTooling)
116+
}
117+
118+
compose.desktop {
119+
application {
120+
mainClass = "compose.project.demo.composedemo.MainKt"
121+
122+
nativeDistributions {
123+
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
124+
packageName = "compose.project.demo.composedemo"
125+
packageVersion = "1.0.0"
126+
}
127+
}
128+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:roundIcon="@mipmap/ic_launcher_round"
9+
android:supportsRtl="true"
10+
android:theme="@android:style/Theme.Material.Light.NoActionBar">
11+
<activity
12+
android:exported="true"
13+
android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN"/>
16+
17+
<category android:name="android.intent.category.LAUNCHER"/>
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package compose.project.demo.composedemo
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.activity.enableEdgeToEdge
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.tooling.preview.Preview
9+
10+
class MainActivity : ComponentActivity() {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
enableEdgeToEdge()
13+
super.onCreate(savedInstanceState)
14+
15+
setContent {
16+
App()
17+
}
18+
}
19+
}
20+
21+
@Preview
22+
@Composable
23+
fun AppAndroidPreview() {
24+
App()
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package compose.project.demo.composedemo
2+
3+
import android.os.Build
4+
5+
class AndroidPlatform : Platform {
6+
override val name: String = "Android ${Build.VERSION.SDK_INT}"
7+
}
8+
9+
actual fun getPlatform(): Platform = AndroidPlatform()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0"/>
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0"/>
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000"/>
30+
</vector>

0 commit comments

Comments
 (0)