AndroidJNIHelper.GetSignature - using Byte parameters is obsolete, use SByte parameters instead. Solution

If you try to pass a byte array from C# script of Unity3D to Android plugin, you will get the following error:

AndroidJNIHelper.GetSignature: using Byte parameters is obsolete, use SByte parameters instead

For example:

C# Unity3d side:

// creation of the plugin
public AndroidJavaObject MyPlugin = new AndroidJavaObject("site.dbu9.test.MyPlugin");
// ...
// calling plugin's function, passing byte[]
if (_filterData.TryDequeue(out byte[] data)) {
  MyPlugin.Call("acceptAudioData", data);
}

Java plugin side:

public void acceptAudioData(byte[] data) {
  mPcmQ.add(data);
}

The code above causes the error message and degrades enormously the performance of the plugin.

Solution

You can use the following code to convert byte[] to sbyte[] and boost the performance:

if (_filterData.TryDequeue(out byte[] data)) {
  sbyte[] sdata = new sbyte[data.Length];
  Buffer.BlockCopy(data, 0, sdata, 0, data.Length);
  MyPlugin.Call("acceptAudioData", sdata);
}

See also