Skip to content

Commit 66b381c

Browse files
committed
Make :demo run on Android
Code is updated referencing a Compose Multiplatform project created with the new [Kotlin Multiplatform Wizard](https://kmp.jetbrains.com/). Opt-in to `ExperimentalWasmDsl` for `wasmJs` to resolve a warning. AGP v8.3.0 is not compatible with Kotlin Multiplatform 1.9.23 yet thus v8.2.2 is used.
1 parent b1e06ae commit 66b381c

File tree

14 files changed

+105
-11
lines changed

14 files changed

+105
-11
lines changed

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dependencies {
1313
implementation(kotlin("gradle-plugin", "1.9.23"))
1414
implementation("org.jetbrains.compose:compose-gradle-plugin:1.6.1")
1515
implementation("com.huanshankeji.team:gradle-plugins:0.5.1")
16+
implementation("com.android.tools.build:gradle:8.2.2")
1617
}

buildSrc/src/main/kotlin/VersionsAndDependencies.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ object DependencyVersions {
22
val huanshankejiComposeWeb = "0.2.2"
33
val kmdc = "0.1.2"
44
val materialIcons = "1.13.12"
5+
6+
object Androidx {
7+
val activityCompose = "1.8.2"
8+
val compose = "1.6.3"
9+
}
510
}

buildSrc/src/main/kotlin/common-conventions.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ plugins {
55
id("org.jetbrains.compose")
66
}
77

8+
group = "com.huanshankeji"
9+
version = "0.1.3-SNAPSHOT"
10+
811
repositories {
912
mavenLocal()
1013
mavenCentral()
@@ -14,7 +17,8 @@ repositories {
1417

1518
kotlin {
1619
jvm() // TODO: `jvm("desktop")`?
17-
// TODO: `android()`?
20+
jvmToolchain(8)
21+
//androidTarget()
1822
@OptIn(ExperimentalWasmDsl::class)
1923
wasmJs()
2024

buildSrc/src/main/kotlin/lib-conventions.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ plugins {
33
// TODO: `id("com.android.library") version "7.2.2"`?
44
id("com.huanshankeji.kotlin-multiplatform-jvm-and-js-browser-conventions")
55
id("com.huanshankeji.kotlin-multiplatform-sonatype-ossrh-publish-conventions")
6+
//id("com.android.library") // not used yet, the `jvm` target seems to be enough
67
}
78

8-
group = "com.huanshankeji"
9-
version = "0.1.3-SNAPSHOT"
10-
119
kotlin {
1210
// move to `common-conventions` if necessary
1311
sourceSets {

demo/build.gradle.kts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
2+
13
plugins {
24
`common-conventions`
5+
id("com.android.application")
36
}
47

58
kotlin {
9+
androidTarget()
10+
611
val outputFileName = "app.js"
12+
13+
@OptIn(ExperimentalWasmDsl::class)
714
wasmJs {
815
browser {
916
commonWebpackConfig {
@@ -12,6 +19,7 @@ kotlin {
1219
}
1320
binaries.executable()
1421
}
22+
1523
js {
1624
browser {
1725
commonWebpackConfig {
@@ -35,6 +43,14 @@ kotlin {
3543
implementation(compose.desktop.currentOs)
3644
}
3745
}
46+
androidMain {
47+
dependencies {
48+
implementation(compose.ui)
49+
50+
implementation("androidx.activity:activity-compose:${DependencyVersions.Androidx.activityCompose}")
51+
implementation("androidx.compose.ui:ui-tooling-preview:${DependencyVersions.Androidx.compose}")
52+
}
53+
}
3854
wasmJsMain {
3955
dependencies {
4056
implementation(compose.ui)
@@ -50,14 +66,30 @@ kotlin {
5066
}
5167
}
5268

69+
val `package` = "$group.compose.material.demo"
70+
5371
compose {
5472
desktop {
5573
application {
56-
mainClass = "com.huanshankeji.compose.material.demo.MainKt"
74+
mainClass = "$`package`.MainKt"
5775
}
5876
}
5977

6078
experimental {
6179
web.application {}
6280
}
6381
}
82+
83+
android {
84+
namespace = `package`
85+
86+
val sdk = 34
87+
compileSdk = sdk
88+
89+
defaultConfig {
90+
applicationId = `package`
91+
minSdk = 24
92+
targetSdk = sdk
93+
versionName = version as String
94+
}
95+
}
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:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:allowBackup="true"
6+
tools:ignore="MissingApplicationIcon"
7+
android:label="@string/app_name"
8+
android:supportsRtl="true"
9+
android:theme="@android:style/Theme.Material.Light.NoActionBar">
10+
<activity
11+
android:exported="true"
12+
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.huanshankeji.compose.material.demo
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.tooling.preview.Preview
8+
9+
class MainActivity : ComponentActivity() {
10+
override fun onCreate(savedInstanceState: Bundle?) {
11+
super.onCreate(savedInstanceState)
12+
13+
setContent { App() }
14+
}
15+
}
16+
17+
@Preview
18+
@Composable
19+
fun AppAndroidPreview() =
20+
App()
21+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Compose Multiplatform Material demo</string>
3+
</resources>

demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo/Main.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

demo/src/jsMain/kotlin/com/huanshankeji/compose/material/demo/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package com.huanshankeji.compose.material.demo
22

33
import org.jetbrains.compose.web.renderComposableInBody
44

5-
actual fun main() {
5+
fun main() {
66
renderComposableInBody { App() }
77
}

0 commit comments

Comments
 (0)