我正在开发一个 KMM 项目,我尝试在我的数据类上使用 @Parcelize 注释,虽然我做了所有的改变,暗示了如何从 android.extensions 迁移到 kotlin-parcelize 的官方文档,Android Studio 仍然没有找到了 kotlinx 包。
这是我收到错误的共享模块中的类:
这是我的共享模块的 build.gradle.kts,这是我使用 @Parcelable 注释的那个。
plugins {
id("com.android.library")
kotlin("multiplatform")
id("kotlinx-serialization")
id("org.jetbrains.kotlin.native.cocoapods")
id("com.squareup.sqldelight")
id("kotlin-parcelize")
}
android {
compileSdkVersion(Versions.compileSdk)
buildToolsVersion(Versions.androidBuildTools)
defaultConfig {
minSdkVersion(Versions.minSdk)
targetSdkVersion(Versions.targetSdk)
versionCode = 1
versionName = "1.0"
}
}
// CocoaPods requires the podspec to have a version.
version = "1.0"
dependencies {
implementation("com.google.firebase:firebase-crashlytics-buildtools:2.8.1")
}
kotlin {
targets {
val sdkName: String? = System.getenv("SDK_NAME")
val isiOSDevice = sdkName.orEmpty().startsWith("iphoneos")
if (isiOSDevice) {
iosArm64("iOS")
} else {
iosX64("iOS")
}
android()
}
cocoapods {
// Configure fields required by CocoaPods.
summary = "Description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
}
sourceSets {
all {
languageSettings.apply {
useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi")
}
}
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation(Coroutines.Core.core)
implementation(Ktor.Core.common)
implementation(Ktor.Json.common)
implementation(Ktor.Logging.common)
implementation(Ktor.Serialization.common)
implementation(SqlDelight.runtime)
implementation(Serialization.runtime)
implementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}")
implementation("org.jetbrains.kotlin:kotlin-parcelize-runtime:${Versions.kotlin}")
}
}
val commonTest by getting {
dependencies {
implementation(Ktor.Mock.jvm)
}
}
val androidMain by getting {
dependencies {
implementation(kotlin("stdlib"))
implementation(Coroutines.Core.core)
implementation(Ktor.android)
implementation(Ktor.Core.jvm)
implementation(Ktor.Json.jvm)
implementation(Ktor.Logging.jvm)
implementation(Ktor.Logging.slf4j)
implementation(Ktor.Mock.jvm)
implementation(Ktor.Serialization.common)
implementation(Serialization.runtime)
implementation(SqlDelight.android)
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation(Ktor.Mock.common)
}
}
val iOSMain by getting {
dependencies {
implementation(Coroutines.Core.core)
implementation(Ktor.ios)
implementation(Ktor.Core.common)
implementation(Ktor.Json.common)
implementation(Ktor.Logging.common)
implementation(Ktor.Serialization.common)
implementation(Serialization.runtimeNative)
implementation(SqlDelight.runtime)
implementation(Ktor.Mock.common)
}
}
val iOSTest by getting {
dependencies {
implementation(Ktor.Mock.native)
}
}
}
}
sqldelight {
database("PetsDatabase") {
packageName = "com.jshvarts.kmp.db"
sourceFolders = listOf("sqldelight")
}
}
和我的项目级别 build.gradle.kts
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.0")
classpath(kotlin("gradle-plugin", version = Versions.kotlin))
classpath(kotlin("serialization", version = Versions.kotlin))
classpath("com.squareup.sqldelight:gradle-plugin:${Versions.sqldelight}")
classpath("com.github.ben-manes:gradle-versions-plugin:0.28.0")
classpath ("androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.navigation}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.serialization}")
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
classpath("org.jetbrains.kotlin:kotlin-parcelize-runtime:${Versions.kotlin}")
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}
plugins {
id("org.jlleitschuh.gradle.ktlint") version "9.2.1"
id ("com.github.ben-manes.versions") version "0.28.0"
}
apply(from = "quality/lint.gradle")
最后关于我正在使用的版本是这样的:
object Versions {
const val navigation = "2.3.0"
const val androidBuildTools = "29.0.2"
const val appCompat = "1.0.2"
const val compileSdk = 29
const val constraintLayout = "1.1.3"
const val coroutines = "1.4.1"
const val kotlin = "1.4.20"
const val ktor = "1.3.5"
const val lifecycle = "2.2.0"
const val material = "1.2.0-alpha05"
const val minSdk = 26
const val picasso = "2.71828"
const val glide = "4.11.0"
const val recyclerView = "1.1.0"
const val serialization = "1.0.1"
const val slf4j = "1.7.30"
const val sqldelight = "1.3.0"
const val swipeToRefreshLayout = "1.0.0"
const val targetSdk = 29
const val timber = "4.7.1"
}
非常感谢您的帮助!