【发布时间】:2022-11-23 01:46:05
【问题描述】:
感觉这非常简单,但我是 Kotlin 和 KMM 的新手><
基本上,我试图在我使用 Android Studio 中的 KMM 插件设置的 KMM 项目中使用 this library 。
我共享的 build.gradle.kts 文件如下所示:`
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
}
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64()
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
version = "1.0"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosApp/Podfile")
framework {
baseName = "shared"
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
implementation("com.kizitonwose.calendar:compose:2.0.3")
}
}
val androidTest by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
}
android {
namespace = "com.example.pilld"
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 32
multiDexEnabled = true
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
implementation("com.kizitonwose.calendar:compose:2.0.3")
}
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.0")
}
** App build.gradle.kts (I believe this is called top-level?):**
buildscript {
dependencies {
classpath("com.android.tools.build:gradle:7.3.0")
}
}
plugins {
//trick: for the same plugin versions in all sub-modules
id("com.android.application").version("7.3.1").apply(false)
id("com.android.library").version("7.3.1").apply(false)
kotlin("android").version("1.7.10").apply(false)
kotlin("multiplatform").version("1.7.10").apply(false)
id("org.jetbrains.compose").version("1.2.1")
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
** And finally the shared/commonMain/Greeting.kt file in which I am trying to use the library:**
package com.example.pilld
//import com.kizitonwose.calendar.*
class Greeting {
private val platform: Platform = getPlatform()
fun greeting(): String {
return "Hello, ${platform.name}!"
}
}
`
还没有尝试太多,只是在做设置。我试过在 Greeting.kt 文件中导入,但它无法识别该库。我是否也应该将它作为依赖项添加到 commonMain sourceSet 中?我也一直在阅读文档,但到处都是,我无法得到直接的答案。任何意见,将不胜感激!
【问题讨论】:
标签: kotlin kotlin-multiplatform kotlin-android-extensions