How can i pass a byte[] data from foreign code (java) to uno method?

Here is what i wanna do:

public static extern(Android) void Init()
    // ...
    byte[] data = getData();

public static extern(Android) void Process(sbyte[] data)
    // work with data

And then it notified this error: byte[] cannot be converted to ByteArray

Hi David, thanks for posting

You are right there is a gap in support here.

I have raised a ticket to fix this and will get on it as soon as I can.

The reason we box uno arrays when passing to java is for performance. We want to avoid unnecessary data copying by default and so we box into a that boxed array has accessors and a copyArray() method which will actually duplicate the data.

Like you worked out, currently foreign code is expecting a to be passed to uno. I’m now wondering if maybe we allow both this and java arrays, and just take the performance hit when we pass down the java array.

Thanks again, I’ll be in contact when there is a fix.

Hi Chris,

Can you please advise on how should the array be passed/received?

I am using (not working):

from Java:


where data is a byte[]

to Uno:

  public void saveLastPicture(sbyte[] newData){
    debug_log("Saved array has length: " + lastPicture.Length);

to copy newData into lastPicture.
lastPicture is an sbyte[]

Also, how to pass the sbyte[] from Uno to Java and use it in Java as byte[]:

void JavaMethod(sbyte[] lastPicture)
     byte[] <= lastPicture

Thanks in advance for your support

Hello, here is a sample project reproducing the error (to be compiled/run on Android only) :

which is: E3104: ‘sbyte[]’ does not contain a member called ‘copyArray’. Could you be missing a package reference?

Ah I think I have confused things :slight_smile: copyArray is a method on the ByteArray java object.

public void TestByteArray(byte[] foo)
    // here foo is a This is a java box
    // around the Uno byte[]
    byte x = foo.get(0);
     // here we get the first byte from the array. This calls
     // down to uno to read the uno array so far we have not
     // copied any data

    foo.set(0, 3);
    // now we set the first byte in the uno array. This
    // modified the uno array
    byte[] bar = foo.copyArray();
    // At this point we copy the entire array into Java memory.
    // making changes to bar will not modify the uno array

Does this help?

To those who stumble onto this thread. If you wish to make an uno int array from java you can now simply call. new;. For more details see here: