Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Plugin: Interfacing with AAR developed in Kotlin involving Kotlin CoroutineScopes

Discussion in 'Android' started by MaguroSenbei, Jul 17, 2020.

  1. MaguroSenbei

    MaguroSenbei

    Joined:
    Apr 21, 2020
    Posts:
    1
    Does anybody have any experience in implementing wrappers for native implementations that involves CoroutineScopes ? Do we have to wrap "Jobs" and "Deferred<T>" 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<MyClass> does it become AndroidJavaOjbect[] or AndroidJavaObject?

    How do we also use generics implemented in Kotlin?
    For example:
    Code (Kotlin):
    1. fun <T> subscribe(class: Class<T>, observer: Observer)
    Do we simply just write something like this?
    Code (CSharp):
    1. myObject.call("subscribe", javaClass, myJavaProxy)
     
    aikqboy and ErnestSurys like this.
  2. aikqboy

    aikqboy

    Joined:
    Sep 11, 2018
    Posts:
    1
    Have you figured out how to work with kotlin coroutine yet?
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,653
    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.