Commit 1ef5c132 authored by jiangyh's avatar jiangyh

新增5个lib

parent f343f8c3
...@@ -39,6 +39,11 @@ kotlin { ...@@ -39,6 +39,11 @@ kotlin {
implementation(compose.components.uiToolingPreview) implementation(compose.components.uiToolingPreview)
implementation(libs.androidx.lifecycle.viewmodelCompose) implementation(libs.androidx.lifecycle.viewmodelCompose)
implementation(libs.androidx.lifecycle.runtimeCompose) implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(project(":lib-core"))
implementation(project(":lib-utils"))
implementation(project(":lib-coroutines"))
implementation(project(":lib-cinterop"))
implementation(project(":lib-api"))
} }
commonTest.dependencies { commonTest.dependencies {
implementation(libs.kotlin.test) implementation(libs.kotlin.test)
......
...@@ -36,12 +36,27 @@ fun App() { ...@@ -36,12 +36,27 @@ fun App() {
} }
AnimatedVisibility(showContent) { AnimatedVisibility(showContent) {
val greeting = remember { Greeting().greet() } val greeting = remember { Greeting().greet() }
// 引入库方法
val coreMsg = remember { com.example.testdemo.lib.core.coreHello() }
val joined = remember { com.example.testdemo.lib.utils.join(listOf("a", "b", "c")) }
val interopOk = remember { com.example.testdemo.lib.cinterop.interopReady() }
val apiVer = remember { com.example.testdemo.lib.api.apiVersion() }
val sum by produceState(initialValue = 0) {
value = com.example.testdemo.lib.coroutines.computeSum(listOf(1, 2, 3))
}
Column( Column(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Image(painterResource(Res.drawable.compose_multiplatform), null) Image(painterResource(Res.drawable.compose_multiplatform), null)
Text("Compose: $greeting") Text("Compose: $greeting")
// 库调用结果展示
Text("lib-core: $coreMsg")
Text("lib-utils.join: $joined")
Text("lib-cinterop.ready: $interopOk")
Text("lib-api.version: $apiVer")
Text("lib-coroutines.sum: $sum")
} }
} }
} }
......
package com.example.testdemo
class OhosPlatform : Platform {
override val name: String = "OpenHarmony"
}
actual fun getPlatform(): Platform = OhosPlatform()
...@@ -12,6 +12,7 @@ androidx-testExt = "1.3.0" ...@@ -12,6 +12,7 @@ androidx-testExt = "1.3.0"
composeMultiplatform = "1.9.2" composeMultiplatform = "1.9.2"
junit = "4.13.2" junit = "4.13.2"
kotlin = "2.2.21" kotlin = "2.2.21"
kotlinx-coroutines = "1.9.0"
[libraries] [libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
...@@ -24,6 +25,7 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a ...@@ -24,6 +25,7 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
androidx-lifecycle-viewmodelCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" } androidx-lifecycle-viewmodelCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtimeCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" } androidx-lifecycle-runtimeCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
[plugins] [plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" } androidApplication = { id = "com.android.application", version.ref = "agp" }
......
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget()
listOf(iosArm64(), iosSimulatorArm64())
sourceSets {
val commonMain by getting
val commonTest by getting
val iosMain by creating { dependsOn(commonMain) }
val iosArm64Main by getting { dependsOn(iosMain) }
val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
}
}
android {
namespace = "com.example.testdemo.lib.api"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
\ No newline at end of file
package com.example.testdemo.lib.api
fun apiVersion(): String = "1.0"
\ No newline at end of file
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget()
listOf(iosArm64(), iosSimulatorArm64())
// 后续如需配置 cinterop,可在此添加 Kotlin/Native 的 cinterop 设置
sourceSets {
val commonMain by getting
val commonTest by getting
val iosMain by creating { dependsOn(commonMain) }
val iosArm64Main by getting { dependsOn(iosMain) }
val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
}
}
android {
namespace = "com.example.testdemo.lib.cinterop"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
\ No newline at end of file
package com.example.testdemo.lib.cinterop
// 后续将使用 cinterop 封装 .so,这里是占位示例
fun interopReady(): Boolean = true
\ No newline at end of file
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget()
listOf(iosArm64(), iosSimulatorArm64())
sourceSets {
val commonMain by getting
val commonTest by getting
// 统一 iOS 源集桥接
val iosMain by creating { dependsOn(commonMain) }
val iosArm64Main by getting { dependsOn(iosMain) }
val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
}
}
android {
namespace = "com.example.testdemo.lib.core"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
\ No newline at end of file
package com.example.testdemo.lib.core
fun coreHello(): String = "core"
\ No newline at end of file
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget()
listOf(iosArm64(), iosSimulatorArm64())
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.kotlinx.coroutines.core)
}
}
val commonTest by getting
val iosMain by creating { dependsOn(commonMain) }
val iosArm64Main by getting { dependsOn(iosMain) }
val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
}
}
android {
namespace = "com.example.testdemo.lib.coroutines"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
\ No newline at end of file
package com.example.testdemo.lib.coroutines
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
suspend fun computeSum(xs: List<Int>): Int = withContext(Dispatchers.Default) { xs.sum() }
\ No newline at end of file
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
}
kotlin {
androidTarget()
listOf(iosArm64(), iosSimulatorArm64())
sourceSets {
val commonMain by getting
val commonTest by getting
val iosMain by creating { dependsOn(commonMain) }
val iosArm64Main by getting { dependsOn(iosMain) }
val iosSimulatorArm64Main by getting { dependsOn(iosMain) }
}
}
android {
namespace = "com.example.testdemo.lib.utils"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}
\ No newline at end of file
package com.example.testdemo.lib.utils
fun join(items: List<String>, sep: String = ",") = items.joinToString(sep)
\ No newline at end of file
...@@ -28,4 +28,6 @@ dependencyResolutionManagement { ...@@ -28,4 +28,6 @@ dependencyResolutionManagement {
} }
} }
include(":composeApp") include(":composeApp")
\ No newline at end of file // 新增 5 个 library 模块
include(":lib-core", ":lib-utils", ":lib-coroutines", ":lib-cinterop", ":lib-api")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment