Как использовать аннотацию @Parcelize в общем модуле многоплатформенного проекта KotlinAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Как использовать аннотацию @Parcelize в общем модуле многоплатформенного проекта Kotlin

Сообщение Anonymous »

Я разрабатывал многоплатформенное приложение на Kotlin, в котором хотел бы использовать аннотацию @Parcelize в своем классе модели. Но в плагинах Kotlin Multiplatform аннотация @Parcelize в версии Kotlin, которую я использую, находится в плагине android.extensions, который применяется к модулю androidApp.
что касается моего build.gradle. ктс(androidApp)

Код: Выделить всё

plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("kotlinx-serialization")
id("androidx.navigation.safeargs.kotlin")
}

android {
compileSdkVersion(Versions.compileSdk)

compileOptions{
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
}

kotlinOptions{
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

kapt{
generateStubs = true
correctErrorTypes = true
}

androidExtensions{
isExperimental = true
}

buildFeatures{
dataBinding = true
viewBinding = true
}

defaultConfig {
applicationId = "com.jshvarts.kmp.android"
minSdkVersion(Versions.minSdk)
targetSdkVersion(Versions.targetSdk)
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}

packagingOptions {
exclude("META-INF/*.kotlin_module")
}
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("stdlib-jdk8", Versions.kotlin))
implementation(Coroutines.android)
implementation(AndroidX.appCompat)
implementation(AndroidX.constraintLayout)
implementation(AndroidX.recyclerView)
implementation(AndroidX.lifecycleExtensions)
implementation(AndroidX.lifecycleViewModelKtx)
implementation(material)
implementation(AndroidX.swipeToRefreshLayout)
implementation(timber)
implementation(picasso)
implementation(AndroidX.navigation)
implementation(AndroidX.navigation_ui)
implementation(Serialization.runtime)
//implementation(Serialization.core)
//Dependency for googlePay
implementation("com.google.android.gms:play-services-wallet:16.0.1")
kapt(databinding)
implementation(glide){
exclude( "com.android.support")
}
kapt(glide)
implementation(project(":shared"))

}
build.gradle.kts(общий)

Код: Выделить всё

plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
//id("kotlinx-serialization")
id("org.jetbrains.kotlin.native.cocoapods")
id("com.squareup.sqldelight")
}
// CocoaPods requires the podspec to have a version.
version = "1.0"

android {
compileSdkVersion(Versions.compileSdk)
buildToolsVersion(Versions.androidBuildTools)

defaultConfig {
minSdkVersion(Versions.minSdk)
targetSdkVersion(Versions.targetSdk)
versionCode = 1
versionName = "1.0"
}
}

version = "1.0"
dependencies {
implementation("com.google.firebase:firebase-crashlytics-buildtools:2.8.1")
implementation(project(mapOf("path"  to ":androidApp")))
}

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(project(":androidApp"))
//implementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}")
//implementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}")
//implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
}
}

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.jvm)
implementation(Serialization.runtime)
//implementation(Serialization.core)
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.jvm)
// 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 {
google()
mavenCentral()
jcenter()
}

dependencies {
classpath("com.android.tools.build:gradle:4.0.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-android-extensions-runtime:${Versions.kotlin}")
}
}

allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}

//TODO("Probar bajando a kotlin version 1.3.72,  y habilitando el android-extensions")
plugins {
//kotlin("jvm") version "${Versions.kotlin}"
id("org.jlleitschuh.gradle.ktlint") version "9.2.1"
id ("com.github.ben-manes.versions") version "0.28.0"
//kotlin("android") version "${Versions.kotlin}" apply false
//id("org.jetbrains.kotlin.plugin.parcelize") version "${Versions.kotlin}"
}
apply(from = "quality/lint.gradle")
Поэтому я создаю ожидаемый и фактический класс Parcelable и Parcelize в androidApp и общих модулях:

Код: Выделить всё

androidApp

actual typealias Parcelable = android.os.Parcelable

actual typealias Parcelize = kotlinx.android.parcel.Parcelize
и в общем модуле

Код: Выделить всё

// Common Code

expect interface Parcelable

@UseExperimental(ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
expect annotation class Parcelize()
Итак, в этом классе я получил следующую ошибку:

Код: Выделить всё

In Parcelable(shared)

Expected interface 'Parcelable' has no actual declaration in module KmpMVVMGooglePay.shared for JVM
Expected interface 'Parcelable' has no actual declaration in module KmpMVVMGooglePay.shared.iOSMain for Native
и в классах Android:

Код: Выделить всё

Actual typealias 'Parcelable' has no corresponding expected declaration

Actual typealias 'Parcelize' has no corresponding expected declaration
Так что же я упустил из фактического/ожидаемого поведения ключевых слов?
Заранее спасибо за помощь!

Подробнее здесь: https://stackoverflow.com/questions/709 ... orm-projec
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»