Gatonito
Gatonito

Reputation: 2174

What is the signature for Java's ByteArray?

I'm trying to call onEventChannel through C++ over JNI:

class MainActivity: FlutterActivity(){
    companion object {
        @JvmStatic
        private fun onEventChannel(b: ByteArray): Int {
            Log.d(TAG, "onEventChannel");
            return 0;
        }
    }

I tried (Ljava/lang/byte;)I and (Ljava/lang/ByteArray;)I for the onEventChannel but none of them work.

What is the signature for java's ByteArray?

Upvotes: 0

Views: 498

Answers (1)

gidds
gidds

Reputation: 18607

(Disclaimer: I don't know Flutter, and haven't used JNI.)

There's no such class as java.lang.byte*, nor java.lang.ByteArray.

On Kotlin/JVM, ByteArray compiles down to a simple primitive array — what would be called byte[] in Java.

And that has the JVM descriptor [B.  (You can see this by printing ByteArray(0).toString(), which starts with [B (before the @ and hash code).  The gory details are in the JVM Spec.)

So I'd suggest trying [B!


(* There is java.lang.Byte, but that's the primitive wrapper class used for boxing bytes.)

Upvotes: 7

Related Questions