Skip to content

BasicMessageChannel's with BinaryCodec aren't sending responses on Android #81875

@gaaclarke

Description

@gaaclarke

Android Code:

class MainActivity: FlutterActivity() {

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        val basicBinary =
            BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.binary", BinaryCodec.INSTANCE)
        basicBinary.setMessageHandler { message, reply -> reply.reply(message) }
        super.configureFlutterEngine(flutterEngine)
    }
}

Flutter Code:

  const BasicMessageChannel<ByteData> basicBinary =
      BasicMessageChannel<ByteData>(
    'dev.flutter.echo.basic.binary',
    BinaryCodec(),
  );

  int size = 0;
  for (int i = 0; i < _numMessages; ++i) {
    final ByteData result = await basicBinary.send(encodedLargeBuffer);
    size += (result == null) ? 0 : result.lengthInBytes;
  }
  if (size != encodedLargeBuffer.lengthInBytes * _numMessages) {
    throw Exception(
        'There is an error with the echo channel, the results don\'t add up: $size');
  }

Seen result:
result is not null, but the lengthInBytes is zero. The exception is getting thrown.

Expected result:
result should be equal to encodedLargeBuffer. This works on iOS, not on Android.

Debugging Info:
I was able to verify that the data is getting received correctly in the channel's handler. I followed the data all the way in the Java debugger and everything looks good. It seems the data is getting lost in the layer below that.

Reproduction Code:
I discovered the problem when authoring #81874

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions