FutureMind/koru

@ToNativeClass/Interface do not work on expected/actual declarations

uliluckas opened this issue · 13 comments

hmm, should @ToNativeInterface work on actual or expected declarations?

  • On expected I get “Expected interface ‘ViewModelNativeProtocol’ has no actual declaration in module <…> for Native”
  • Same if expected and actual are annotated.
  • Annotating only actual in iosMain seems to do nothing

If this is fixed, it would be great if it would be documented, which part of expected/actual to annotate.

Just to clarify, you have expect abstract class ViewModel in shared module, on Android it's a typealias to the Google ViewModel and on ios module what it is and what functions / properties does it have? Are any of them suspend functions or Flows? What do you use the ViewModel in Swift code for?

I have same problem.
Added @ToNativeClass annotation to the class. But A wrapper was not generated.

Did you use ksp or kapt?
The class you annotated was in common code or a different source set?

I will assume that you tried ksp and ios source set. By design this library analyses the common soirce and generates ios code. If you would like to use it differently, can you explain your use case to me? I'm trying to understand different ways people are using the library.

Did you use ksp or kapt?

ksp.

The class you annotated was in common code or a different source set?

common code.

Hmmm, I'm going to need more details then. Can you maybe post some code and the gradle config that you tried?

v0.10.0 (use kapt, Kotlin v1.6.20) is work.
But v0.11.1 (use ksp Kotrlin v1.7.0) is not work.

For now, I think use v0.10.0.

Can you maybe post some code and the gradle config that you tried?

If I can show the code, I will show it tomorrow. 🙏

@uluckas I think I might have fixed your usecase. I'm missing code details, so it's just my understanding how you would use it, but still, should work. Please take a look at 0.12.0-SNAPSHOT and let me know if it works for you. Here's how to use it.

FutureMind/koru-example@master...fix/#49-expect-actual

@yamakentoc if you can show your gradle config, that would be welcome, in the meantime, I think the problem might b that you set this

koru {
    nativeSourceSetNames = listOf("iosMain")
}

and your ios source set is named differently, e.g. appleMain. I'm gonna add a warning for that in the build process.

@micHar
Sorry for replying so late.
↓ This is gradle config.

// HogeHogeHoge/shared/build.gradle.kts
// kotlin version: 1.7,0

val ktorVersion = "2.0.1"
val kotlinCoroutineVersion = "1.6.3"

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("com.google.devtools.ksp") version "1.7.0-1.0.6"
    id("com.futuremind.koru").version("0.11.0")
    kotlin("plugin.serialization")
}

kotlin {
    android()

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "HogeHogeHoge"
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                //Coroutines
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutineVersion-native-mt")
                //Network
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-serialization:$ktorVersion")
                // JSON Serialization
                implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
                implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
                // client mock
                implementation("io.ktor:ktor-client-mock:$ktorVersion")
                // koru
                implementation("com.futuremind:koru:0.11.1")
                // firebase
                implementation("dev.gitlive:firebase-auth:1.6.1")
            }
        }

        val androidMain by getting {
            dependencies {
                //Network
                implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }

        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)
            dependencies {
                //Network
                implementation("io.ktor:ktor-client-darwin:$ktorVersion")
            }
        }
    }
}

android {
    compileSdk = 31
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 27
        targetSdk = 31
    }
}

koru {
    nativeSourceSetNames = listOf("iosMain")
}

your ios source set is named differently, e.g. appleMain

My project's ios source is iosMain.
名称未設定

One thing that I can see here is that you have 0.11.0 for gradle plugin and 0.11.1 for the library. Both should be 0.11.1. I'm not sure if it's gonna fix the issue though.

@micHar
0.11.0 and 0.11.1 is written in README. so I wrote like that.
https://github.com/FutureMind/koru#download

I changed 0.11.0 but did not fix

I moved the issue to #51, because it's not related to the original one. Let's continue there.

One thing to note is that this will apparently only work with KSP. KAPT ignores expect classes during annotation processing - in both tests and production code. Probably completely incompatible.

Released 0.12.0 which handles expect actual and also added an example of handling KaMPKit like shared viewmodels in the example repo.