Plugin: Interfacing with AAR developed in Kotlin involving Kotlin CoroutineScopes

Does anybody have any experience in implementing wrappers for native implementations that involves CoroutineScopes ? Do we have to wrap “Jobs” and “Deferred” to have them work? What about suspend functions?

How do I safely call join, await and cancel for these scenarios?

I am also not entirely sure on the data type association between C# and Kotlin especially for the return type and parameter types for function calls.

For example:
If I’m returning a ByteArray from Kotlin does it associate it to byte[ ] or AndroidJavaObject in C#?
The same for Array does it become AndroidJavaOjbect[ ] or AndroidJavaObject?

How do we also use generics implemented in Kotlin?
For example:

fun <T> subscribe(class: Class<T>, observer: Observer)

Do we simply just write something like this?

myObject.call("subscribe", javaClass, myJavaProxy)
2 Likes

Have you figured out how to work with kotlin coroutine yet?

The same type can be represented several ways on Unity C# side. Any Java object can go like AndroidJavaObject, arrays of Java objects can be represented as AndroidJavaObject[ ] etc.
Our mappins is done in Java terms. Kotlin ByteArray is byte[ ] in Java, so in C# it is sbyte[ ].

In Java generics are gone when compiled, I assume it is also true for Kotlin, so for generic types remove and generic marker and use objects.