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. Dismiss Notice

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

Discussion in 'Android' started by push-pop, Aug 18, 2020.

  1. push-pop

    push-pop

    Joined:
    Jun 29, 2017
    Posts:
    28
    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:

    Code (CSharp):
    1. public struct FileStruct
    2. {
    3.     public string path;
    4.     public long byteOffset;
    5.     public long assetLength;
    6. }
    7. public class PluginClass{
    8.     public override void DoSomethingNative(FileStruct[] files)
    9.     {
    10.         pluginClass.Call("doSomethingNative",  files);
    11.     }
    12. }
    13.  
    Then on the android side I have the same struct defined as:

    Code (CSharp):
    1.  
    2. package com.my.packagename;
    3.  
    4. public class FileStruct {
    5.     public String path;
    6.     public long byteOffset;
    7.     public long assetLength;
    8. }
    9.  
    10.  
    11. public class PluginClass{
    12.     public void doSomethingNative(FileStruct[] assets) {
    13.         for (FileStruct asset : assets) {
    14.             Log.i(TAG, "doSomethingNative: path: "
    15.                     + asset.path
    16.                     + " byteOffset: "
    17.                     + asset.byteOffset
    18.                     + " assetLength: "
    19.                     + asset.assetLength);
    20.         }
    21.     }
    22. }
    23.  
    24.  
    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#?
     
  2. push-pop

    push-pop

    Joined:
    Jun 29, 2017
    Posts:
    28
    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.
     
  3. mc_fragezeichen

    mc_fragezeichen

    Joined:
    Aug 17, 2020
    Posts:
    10
    I'm having a similar issue. Sending a json or string is not an option as the it slows down my communication (~10 ms)
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

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