-
Notifications
You must be signed in to change notification settings - Fork 555
Description
I*m using Android Studio to buld an Android service and VisualStudio 2019 to build an App that uses this Service (have to do it this way).
There seems to be an issue when using out
arrays like int[]
or byte[]
.
Steps to Reproduce
- AIDL file with a function like
int GetByte(out byte[] myByte);
- Implement a Java-Service using Android-Studio that implements AIDL interface and write 1 byte to the out parameter
myByte
- Implement a Xamarin App that uses the Service and call
GetByte
.
Expected Behavior
The App shoud receive the byte correctly.
Actual Behavior
It always results in an Exception:
java.lang.RuntimeException: bad array lengths
at android.os.Parcel.readByteArray(Parcel.java:2233)
To me it looks like the code generator has a bug. I compared the generated Java code (Android Studio) and the corresponding C# code (Visual Studio):
Java:
@Override public int GetByte(byte[] myByte) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
int _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
if ((count==null)) {
_data.writeInt(-1);
}
else {
_data.writeInt(count.length);
}
boolean _status = mRemote.transact(Stub.TRANSACTION_GetByte, _data, _reply, 0);
if (!_status && getDefaultImpl() != null) {
return getDefaultImpl().GetByte(count);
}
_reply.readException();
_result = _reply.readInt();
_reply.readByteArray(count);
}
finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
C#
public int SIS_GetByte (byte [] myByte)
{
global::Android.OS.Parcel __data = global::Android.OS.Parcel.Obtain ();
global::Android.OS.Parcel __reply = global::Android.OS.Parcel.Obtain ();
int __result = default (int);
try {
__data.WriteInterfaceToken (descriptor);
remote.Transact (IScaleInterfaceServiceStub.TransactionSIS_GetByte, __data, __reply, 0);
__reply.ReadException ();
__result = __reply.ReadInt ();
__reply.ReadByteArray (count);
} finally {
__reply.Recycle ();
__data.Recycle ();
}
return __result;
}
The corresponding _data.writeInt
before remote.Transact
seems to be missing for the C# code. Thus the error java.lang.RuntimeException: bad array lengths makes sense to me.
Version Information
Xamarin 16.5.000.533 (d16-5@9152e1b)
Visual Studio-Erweiterung, um Entwicklung für Xamarin.iOS und Xamarin.Android zu ermöglichen.
Xamarin.Android SDK 10.2.0.100 (d16-5/988c811)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: c0c5c78
Java.Interop: xamarin/java.interop/d16-5@fc18c54
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b
Log File
java.lang.ArrayIndexOutOfBoundsException: byte[] offset=0 length=1 dst.length=0