Starting with jnigen (0.16.0-wip versions onwards), when generating Dart bindings for Java/Kotlin methods that return generic collections like java.util.List or java.util.Map, jnigen generates statically invalid strict type mappings that fail Dart compilation.
Given a Kotlin method that returns a nullable List or Map format (such as from pigeon):
interface NIHostIntegrationCoreApi {
fun echoList(list: List<Any?>?): List<Any?>?
fun echoMap(map: Map<Any, Any>?): Map<Any, Any>?
}
jnigen generates the following JObject wrapper back into Dart:
static final _id_echoList = NIHostIntegrationCoreApi._class.instanceMethodId(
r'echoList',
r'(Ljava/util/List;)Ljava/util/List;',
);
jni$_.JList<jni$_.JObject?> echoList(
jni$_.JList<jni$_.JObject?> list,
) {
...
return $o.as<jni$_.JList<jni$_.JObject?>>(
jni$_.JList.type,
releaseOriginal: true,
);
}
When attempting to flutter build or run dart compilation against the generated bindings, compilation fails with the following errors for every JList and JMap usage:
Error: The argument type 'JType<JList<dynamic>>' can't be assigned to the parameter type 'JType<JList<JObject?>>'.
- 'JType' is from 'package:jni/src/types.dart'.
- 'JList' is from 'package:jni/src/core_bindings.dart'.
- 'JObject' is from 'package:jni/src/jobject.dart'.
jni$_.JList.type,
^
Error: The argument type 'JType<JMap<dynamic, dynamic>>' can't be assigned to the parameter type 'JType<JMap<JObject?, JObject?>>'.
jni$_.JMap.type,
^
Starting with jnigen (0.16.0-wip versions onwards), when generating Dart bindings for Java/Kotlin methods that return generic collections like java.util.List or java.util.Map, jnigen generates statically invalid strict type mappings that fail Dart compilation.
Given a Kotlin method that returns a nullable List or Map format (such as from pigeon):
jnigen generates the following JObject wrapper back into Dart:
When attempting to flutter build or run dart compilation against the generated bindings, compilation fails with the following errors for every JList and JMap usage: