【Android】How to use @Parcelize

How to use @Parcelize

参照:

https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.parcelize

gradle:

// project build.gradle
plugins {
    ..
    id "org.jetbrains.kotlin.android" version "1.4.20" apply false
}

// app build.gradle
plugins {
    ..
    id 'kotlin-parcelize'
}

kts:

// project build.gradle.kts
plugins {
    ..
    kotlin("android") version "1.4.20" apply false
}

// app build.gradle.kts
plugins {
    ..
    id("kotlin-parcelize")
}

或者使用 Legacy 的gradle配置

  • Step 1. Update to latest kotlin version - 1.9.22 and replace

apply plugin: ‘kotlin-android-extensions’

with this ->

apply plugin: 'kotlin-parcelize'
  • Step 2. Remove this code from the android {}

androidExtensions {
experimental = true
}

  • Step 3. Finally, replace old import ->

import kotlinx.android.parcel.Parcelize

with new import

import kotlinx.parcelize.Parcelize

猜你喜欢

转载自blog.csdn.net/weixin_42473228/article/details/142727181