找回密码
 立即注册
查看: 263|回复: 0

记录kotlinx.serialization 报错 Mark the class as @Serializable or provide the ser

[复制链接]
发表于 2022-6-20 15:28 | 显示全部楼层 |阅读模式
1.plugins忘记加kotlinx-serialization

解决办法:moudle目录build.gradle.kts 下加入

(```

plugins{

kotlin("plugin.serialization")

}

```)

新的build.gradle方式下加入

(```

plugins{

id 'kotlinx-serialization'

}

```)

旧的build.gradle方式下加入

(```

applyplugin:'kotlinx-serialization'

```)

使用kotlinx-serialization 必须设置的三个地方

根目录build.gradle配置kotlin-gradle-plugin和kotlin-serialization

moudle plugins配置kotlin-serialization

module dependencies配置kotlinx-serialization-json

下面是各种场景下的写法

根目录build.gradle.kts

(```

{

...

dependencies{

classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0")

classpath("com.android.tools.build:gradle:7.2.1")

classpath("org.jetbrains.kotlin:kotlin-serialization:1.7.0")

}

...

}

```)

根目录build.gradle

(```

{

...

dependencies{

classpath "com.android.tools.build:gradle:7.2.1"

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"

classpath "org.jetbrains.kotlin:kotlin-serialization:1.7.0"

}

...

}

```)

moudle目录 build.gradle.kts

(```

plugins{

  kotlin("multiplatform")

kotlin("native.cocoapods")

kotlin("plugin.serialization")

//kotlin("kotlinx-serialization")

  id("com.android.library")

//id("kotlinx-serialization")

}

version ="1.0"

kotlin {

  android()

iosX64()

iosArm64()

iosSimulatorArm64()

cocoapods {

    summary ="Some description for the Shared Module"

    homepage ="Link to the Shared Module homepage"

    ios.deploymentTarget ="14.1"

    podfile =project.file("../iosApp/Podfile")

framework{

      baseName ="shared"

    }

}

  sourceSets {

    val commonMain by getting {

      dependencies{

        api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")

implementation("com.badoo.reaktive:reaktive:1.2.2")

implementation("com.badoo.reaktive:reaktive-annotations:1.2.2")

implementation("com.badoo.reaktive:utils:1.2.2")

}

}

    val commonTest by getting {

      dependencies{

        implementation(kotlin("test"))

}

}

    val androidMain by getting{

      dependencies{

        //api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")

        api ("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.3.2")

api ("org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.3.2")

api("com.google.code.gson:gson:2.8.2")

api(files("libs/slf4j-api-1.7.21.jar"))

}

}

    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 {

  compileSdk =32

  sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")

defaultConfig{

    minSdk =21

    targetSdk =32

  }

}

//dependencies {

//  api(files("libs/slf4j-api-1.7.21.jar"))

//}

```)
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-26 10:21 , Processed in 0.088987 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表