Passing struct through androidJavaObject.Call results in Exception: JNI: Unknown signature for type

Hi all,

Wondering if anyone knows if it is possible to send a C# struct through the JNI as a parameter.

I have a setup that is like this:

public struct FileStruct
{
    public string path;
    public long byteOffset;
    public long assetLength;
}
public class PluginClass{
    public override void DoSomethingNative(FileStruct[] files)
    {
        pluginClass.Call("doSomethingNative",  files);
    }
}

Then on the android side I have the same struct defined as:

package com.my.packagename;

public class FileStruct {
    public String path;
    public long byteOffset;
    public long assetLength;
}


public class PluginClass{
    public void doSomethingNative(FileStruct[] assets) {
        for (FileStruct asset : assets) {
            Log.i(TAG, "doSomethingNative: path: "
                    + asset.path
                    + " byteOffset: "
                    + asset.byteOffset
                    + " assetLength: "
                    + asset.assetLength);
        }
    }
}

Currently this throws the error: ```Exception: JNI: Unknown signature for type ‘FileStruct’ (obj = FileStruct) equal
at UnityEngine._AndroidJNIHelper.GetSignature (System.Object obj) [0x00356] in <3c22a197ab60454cb70124c69f2248be>:0


Is there any way to get something like this to work?? Do I need to create the AndroidJavaObject manually in C#?

I ended up solving this by serializing the array to a JSON object and passing that through to my plugin. I suppose it’s an OK solution.

I’m having a similar issue. Sending a json or string is not an option as the it slows down my communication (~10 ms)

No, you cannot do that. You can only use data types that have a direct supported counterpart on Java side, which is primitives, string and AndroidJavaObject/Proxy/Runnable.

Yes, that is precisely what you have to do.