+
Skip to content

angcyo/KMPDemo

Repository files navigation

2025-03-31

Jetpack Compose 使用入门

Kotlin Multiplatform

Compose Multiplatform

Kotlin Multiplatform Wizard

ComposeDemo

Web

Gradle -> Tasks -> other -> wasmJsRun

Desktop

Gradle -> Tasks -> compose desktop -> run

project

settings.gradle.kts

rootProject.name = "KMPDemo"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

pluginManagement {
    repositories {
        google {
            mavenContent {
                includeGroupAndSubgroups("androidx")
                includeGroupAndSubgroups("com.android")
                includeGroupAndSubgroups("com.google")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositories {
        google {
            mavenContent {
                includeGroupAndSubgroups("androidx")
                includeGroupAndSubgroups("com.android")
                includeGroupAndSubgroups("com.google")
            }
        }
        mavenCentral()
    }
}

include(":composeApp")
include(":server")
include(":shared")

build.gradle.kts

plugins {
    // this is necessary to avoid the plugins to be loaded multiple times
    // in each subproject's classloader
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.androidLibrary) apply false
    alias(libs.plugins.composeMultiplatform) apply false
    alias(libs.plugins.composeCompiler) apply false
    alias(libs.plugins.kotlinJvm) apply false
    alias(libs.plugins.kotlinMultiplatform) apply false
}

//--

plugins {
    // this is necessary to avoid the plugins to be loaded multiple times
    // in each subproject's classloader
    id("com.android.application").version(libs.versions.agp).apply(false)
    //id("com.android.application").version("8.5.2").apply(false)
    id("com.android.library").version("8.5.2").apply(false)
    id("org.jetbrains.kotlin.plugin.compose").version("2.1.10").apply(false)
    //
    id("org.jetbrains.compose").version("1.7.3").apply(false) //diff
    id("org.jetbrains.kotlin.jvm").version("2.1.10").apply(false) //diff //desktop
    id("org.jetbrains.kotlin.multiplatform").version("2.1.10").apply(false) //diff
}

app

build.gradle.kts

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.composeMultiplatform)
    //
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.composeCompiler)
}

//--

plugins {
  id("com.android.application")
  id("org.jetbrains.kotlin.plugin.compose")
  //
  id("org.jetbrains.kotlin.multiplatform") //diff
  id("org.jetbrains.compose")              //diff
}

dependencies

androidMain.dependencies {
  //https://mvnrepository.com/artifact/org.jetbrains.compose.ui/ui-tooling-preview 1.7.3
  implementation(compose.preview) //implementation("org.jetbrains.compose.ui:ui-tooling-preview")
  //https://mvnrepository.com/artifact/androidx.activity/activity-compose
  implementation(libs.androidx.activity.compose) //implementation("androidx.activity:activity-compose:1.10.1")
}
commonMain.dependencies {
  //https://mvnrepository.com/artifact/org.jetbrains.compose.runtime/runtime 1.7.3
  implementation(compose.runtime) //implementation("org.jetbrains.compose.runtime:runtime")
  //https://mvnrepository.com/artifact/org.jetbrains.compose.foundation/foundation 1.7.3
  implementation(compose.foundation)  //implementation("org.jetbrains.compose.foundation:foundation")
  //https://mvnrepository.com/artifact/org.jetbrains.compose.material/material 1.7.3
  implementation(compose.material) //implementation("org.jetbrains.compose.material:material")
  //https://mvnrepository.com/artifact/org.jetbrains.compose.material3/material3 1.7.3
  //implementation(compose.material3) //implementation("org.jetbrains.compose.material3:material3")
  //https://mvnrepository.com/artifact/org.jetbrains.compose.ui/ui 1.7.3
  implementation(compose.ui) //implementation("org.jetbrains.compose.ui:ui")
  //https://mvnrepository.com/artifact/org.jetbrains.compose.components/components-resources 1.7.3
  implementation(compose.components.resources) //implementation("org.jetbrains.compose.components:components-resources")
  //https://mvnrepository.com/artifact/org.jetbrains.compose.components/components-ui-tooling-preview 1.7.3
  implementation(compose.components.uiToolingPreview) //implementation("org.jetbrains.compose.components:components-ui-tooling-preview")
  //https://mvnrepository.com/artifact/org.jetbrains.androidx.lifecycle/lifecycle-viewmodel 2.8.4
  implementation(libs.androidx.lifecycle.viewmodel) //implementation("org.jetbrains.androidx.lifecycle:lifecycle-viewmodel:2.8.4")
  //https://mvnrepository.com/artifact/org.jetbrains.androidx.lifecycle/lifecycle-runtime-compose 2.8.4
  implementation(libs.androidx.lifecycle.runtime.compose) //implementation("org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose:2.8.4")
  implementation(projects.shared) //
}

This is a Kotlin Multiplatform project targeting Android, iOS, Web, Desktop, Server.

  • /composeApp is for code that will be shared across your Compose Multiplatform applications. It contains several subfolders:

    • commonMain is for code that’s common for all targets.
    • Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name. For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app, iosMain would be the right folder for such calls.
  • /iosApp contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform, you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.

  • /server is for the Ktor server application.

  • /shared is for the code that will be shared between all targets in the project. The most important subfolder is commonMain. If preferred, you can add code to the platform-specific folders here too.

Learn more about Kotlin Multiplatform, Compose Multiplatform, Kotlin/Wasm

We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel #compose-web. If you face any issues, please report them on GitHub.

You can open the web application by running the :composeApp:wasmJsBrowserDevelopmentRun Gradle task.

About

2025-03-31

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载