Skip to content

Conversation

@liamappelbe
Copy link
Contributor

Working on #558. For my test case I modified the JNIgen Kotlin example to add a Thinker interface, which has a suspend fun I'm implementing in Dart.

Main files to look at:

  • pkgs/jni/lib/src/kotlin.dart, where I'm defining a new KotlinContinuation that helps with continuation resuming.
  • pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart around line 376. I've manually modified the bindings to use the new KotlinContinuation class.

Currently getting this exception in pkgs/jni/lib/src/kotlin.dart at line 50:

E/flutter (15591): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Exception in Java code called through JNI: java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation
E/flutter (15591): 
E/flutter (15591): java.lang.ClassCastException: kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to kotlinx.coroutines.internal.DispatchedContinuation
E/flutter (15591):  at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:166)
E/flutter (15591):  at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
E/flutter (15591):  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
E/flutter (15591):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (15591):  at android.os.MessageQueue.next(MessageQueue.java:346)
E/flutter (15591):  at android.os.Looper.loopOnce(Looper.java:189)
E/flutter (15591):  at android.os.Looper.loop(Looper.java:317)
E/flutter (15591):  at android.app.ActivityThread.main(ActivityThread.java:8705)
E/flutter (15591):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter (15591):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
E/flutter (15591):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
E/flutter (15591): 
E/flutter (15591): 
E/flutter (15591): #0      Jni.throwException (package:jni/src/jni.dart:196:5)
E/flutter (15591): #1      _check (package:jni/src/accessors.dart:17:9)
E/flutter (15591): #2      JThrowableCheckMethod.check (package:jni/src/accessors.dart:118:5)
E/flutter (15591): #3      GlobalJniEnv.CallVoidMethodA (package:jni/src/third_party/global_env_extensions.dart:453:45)
E/flutter (15591): #4      jvoidType._instanceCall (package:jni/src/jprimitives.dart:393:20)
E/flutter (15591): #5      JInstanceMethodId.call.<anonymous closure> (package:jni/src/jclass.dart:111:25)
E/flutter (15591): #6      using (package:ffi/src/arena.dart:127:31)
E/flutter (15591): #7      JInstanceMethodId.call (package:jni/src/jclass.dart:109:12)
E/flutter (15591): #8      KotlinContinuation.resumeWith (package:jni/src/kotlin.dart:37:18)
E/flutter (15591): #9      KotlinContinuation.resumeWithFuture.<anonymous closure> (package:jni/src/kotlin.dart:42:9)
E/flutter (15591): #10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:948:45)
E/flutter (15591): #11     Future._propagateToListeners (dart:async/future_impl.dart:977:13)
E/flutter (15591): #12     Future._completeWithValue (dart:async/future_impl.dart:720:5)
E/flutter (15591): <asynchronous suspension>
E/flutter (15591): 

Seems to be some internal detail of the Kotlin continuation system that I'm not familiar with.

@github-actions
Copy link

PR Health

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/hooks_runner/test_data/download_assets/hook/build.dart
pkgs/jni/test/debug_release_test.dart
pkgs/objective_c/example/command_line/lib/main.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
jni Breaking 0.15.2 0.15.3-wip 0.16.0
Got "0.15.3-wip" expected >= "0.16.0" (breaking changes)
⚠️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry
Package Changed Files
package:jni pkgs/jni/lib/_internal.dart
pkgs/jni/lib/src/kotlin.dart

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant