Ignore Jvm annotations
[!CAUTION] Declaration annotated with '@OptionalExpectation' can only be used in common module sources
A method like this:
@JvmOverloads
@NativeCoroutines
open fun load(
key: CharSequence,
retry: Boolean = true
): Flow<String> = flow { emit("Hello World") }
Will result in the following:
@JvmOverloads
@ObjCName(name = "load")
public fun Test.loadNative(key: CharSequence, retry: Boolean): NativeFlow<String> = load(key, retry).asNativeFlow(null)
The above error is basically caused by the @JvmOverloads (same with @JvmStatic probably) annotation, can you just ignore/remove it when generating code with KSP, so it looks like this then:
@ObjCName(name = "load")
public fun Test.loadNative(key: CharSequence, retry: Boolean): NativeFlow<String> = load(key, retry).asNativeFlow(null)
Hi! Could you try the k2Mode and let me know how that works for you?:
// build.gradle.kts
nativeCoroutines {
k2Mode = true
}
In K2 mode only some specific annotations are copied and all others are ignored.
@rickclephas K2 mode does not seem to work. It does not generate any sources, tested with KSP1 and KSP2.
As soon as K2 mode is turned off, it generates the sources again but with the error.
The K2 mode doesn't use KSP anymore. It generates the required declarations with a Kotlin Compiler plugin. With the compiler plugin you won't see generated source files, but the declarations should be there if you try to use them from Swift. If that isn't the case could you share some more details about your setup (Kotlin and dependency versions) and any relevant logs?
Got it, it's working now!
And it's even better for my use-case since I use it in a library and KSP causes some trouble when publishing sometimes. You can close this issue if you want (or not), not sure if you still want to fix the KSP part then.
FYI K2 mode is now the default and KSP support will be removed in the next release, so this should no longer be an issue.