Repository navigation
[generator] Bind Kotlin suspend functions as Task-returning methods - #13583
Open
jonathanpeppers wants to merge 24 commits into
Open
jonathanpeppers wants to merge 24 commits into
jonathanpeppers wants to merge 24 commits into
Conversation
kotlinc writes @NotNull/@nullable annotations, but these are RuntimeInvisible and tools such as R8 can remove them. The Kotlin metadata (kept at runtime) still tells which types can be null. KotlinFixups now records non-null reference types from Kotlin metadata on constructor and function parameters, extension receivers, return types, property getters/setters and fields. XmlClassDeclarationBuilder uses this as a fallback after Java annotations, so api.xml gets the same not-null/return-not-null attributes and the generator emits the correct C# nullable annotations. Type parameters, platform (flexible) types, lateinit fields and suspend function return types are not marked as non-null. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A value class with a nullable backing type, such as \�alue class Maybe(val value: String?)\, is unboxed to a nullable JVM type. Only mark a type as non-null when the Kotlin type maps to the JVM descriptor. Also reject any type with flexible capabilities. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`KotlinFixups.FindKotlinFunctionMetadata()` finds the Kotlin function
for each Java method. When more than one Kotlin function matched:
* The `JvmSignature` and constructed-signature checks used
`SingleOrDefault()`, which threw. The outer `catch` then skipped
all remaining Kotlin fixups for the class.
* The fallback type check returned the first match. For example,
kotlinc emits a bridge `put(Ljava/lang/Object;)V` for a generic
override. Both `put(String)` and an `@PublishedApi internal`
`put(Int)` match it, and the internal one hid the bridge.
Now all three checks collect the matches. If more than one Kotlin
function matches, the Java method gets no Kotlin fixups. For a public
method, class-parse reports the new warning XA4268. For a synthetic
method, such as a bridge, it writes a debug message only, because the
method is not public API and a warning would be noise.
The message is in `Java.Interop.Localization`, as
`Xamarin.Android.Tools.Bytecode` now references that project.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…methods Remove comments and test assertions that add no value. A rubber-duck review found that private and package-private methods could also cause XA4268. These methods are not bound and get no Kotlin fixups, so write only a debug message for them, as for synthetic methods. Keep the test assertions independent of the English message text, so they also pass after the message is localized. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
JNI peer-lifetime and generated-name collision bugs can cause runtime failures and uncompilable bindings, while the cancellation test does not verify that the Kotlin coroutine actually exits.
3 open issues
What changed in this PR
Adds Task-based bindings for Kotlin suspend functions, connecting Kotlin metadata parsing, C# binding generation, and the .NET for Android runtime.
Changes:
- Preserves suspend-result metadata and generates
*Asyncwrappers with optional cancellation tokens. - Adds a runtime continuation bridge for results, exceptions, and cancellation, plus R8 retention rules.
- Adds bytecode, generator, binding-build, and device integration tests.
| File | Description |
|---|---|
| tests/Xamarin.Android.Tools.Bytecode-Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj | Embeds the suspend fixture. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/KotlinSuspendTests.cs | Tests suspend-result metadata extraction. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/kotlin-gradle/src/main/kotlin/SuspendFunctions.kt | Adds Kotlin suspend test cases. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/kotlin-gradle.targets | Tracks the compiled fixture output. |
| tests/MSBuildDeviceIntegration/Tests/KotlinSuspendTests.cs | Exercises results, failures, and cancellation on-device with R8. |
| tests/generator-Tests/Unit-Tests/KotlinSuspendTests.cs | Checks generated Task wrappers. |
| tests/generator-Tests/Unit-Tests/KotlinInlineClassEndToEndTests.cs | Shares the fixture-loading helper. |
| tests/generator-Tests/generator-Tests.csproj | Embeds the suspend fixture for generator tests. |
| src/Xamarin.SourceWriter/Models/MethodParameterWriter.cs | Supports default parameter values. |
| src/Xamarin.Android.Tools.Bytecode/XmlClassDeclarationBuilder.cs | Exports suspend-result metadata to XML. |
| src/Xamarin.Android.Tools.Bytecode/Methods.cs | Stores suspend-result metadata. |
| src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs | Recognizes suspend functions and their result types. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs | Checks Task wrappers for DataStore bindings. |
| src/Xamarin.Android.Build.Tasks/Resources/proguard_xamarin.cfg | Retains reflectively accessed Kotlin members. |
| src/Xamarin.Android.Build.Tasks/Resources/proguard_typemap.cfg | Adds Kotlin retention rules for typemap builds. |
| src/Xamarin.Android.Build.Tasks/Resources/proguard_typemap_coreclr.cfg | Adds Kotlin retention rules for CoreCLR builds. |
| src/Mono.Android/PublicAPI/API-37/PublicAPI.Unshipped.txt | Records the new runtime API. |
| src/Mono.Android/PublicAPI/API-37.2/PublicAPI.Unshipped.txt | Records the new runtime API. |
| src/Mono.Android/PublicAPI/API-37.1/PublicAPI.Unshipped.txt | Records the new runtime API. |
| src/Mono.Android/PublicAPI/API-36/PublicAPI.Unshipped.txt | Records the new runtime API. |
| src/Mono.Android/PublicAPI/API-36.1/PublicAPI.Unshipped.txt | Records the new runtime API. |
| src/Mono.Android/PublicAPI/API-35/PublicAPI.Unshipped.txt | Records the new runtime API. |
| src/Mono.Android/Mono.Android.csproj | Includes the coroutine bridge. |
| src/Mono.Android/Android.Runtime/KotlinCoroutines.cs | Bridges Kotlin continuations to managed Tasks. |
| src/Java.Interop.Tools.JavaTypeSystem/Adapters/JavaXmlApiImporter.cs | Preserves suspend metadata through type processing. |
| src/generator/SourceWriters/KotlinSuspendMethodWrapper.cs | Generates Task-returning suspend wrappers. |
| src/generator/SourceWriters/InterfaceExtensionsClass.cs | Adds suspend wrappers as interface extensions. |
| src/generator/SourceWriters/BoundInterface.cs | Integrates static wrappers and extension generation. |
| src/generator/SourceWriters/BoundClass.cs | Integrates class and nested-interface wrappers. |
| src/generator/Java.Interop.Tools.Generator.ObjectModel/Method.cs | Stores and clones suspend-result metadata. |
| src/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs | Imports suspend-result metadata for generation. |
Review effort: Balanced
Comment on lines
+107
to
+108
| if (job != null) | ||
| types.CancelJob?.Invoke (job, new Java.Lang.Object [1]); |
Comment on lines
+138
to
+140
| var reference = types.FailureException.Get (value)?.PeerReference ?? default; | ||
| SetException (JniEnvironment.Runtime.GetExceptionForThrowable (ref reference, JniObjectReferenceOptions.Copy) ?? | ||
| new InvalidOperationException ("Kotlin returned an invalid failure.")); |
Comment on lines
+34
to
+51
| if (selfType != null) | ||
| Parameters.Add (new MethodParameterWriter ("self", new TypeReferenceWriter (selfType)) { IsExtension = true }); | ||
|
|
||
| var parameters = new ParameterList (); | ||
| foreach (var p in method.Parameters.Take (method.Parameters.Count - 1)) | ||
| parameters.Add (p); | ||
| this.AddMethodParameters (parameters, opt); | ||
|
|
||
| var token = parameters.Any (p => opt.GetSafeIdentifier (p.Name) == "cancellationToken") ? "__cancellationToken" : "cancellationToken"; | ||
| Parameters.Add (new MethodParameterWriter (token, new TypeReferenceWriter ("global::System.Threading.CancellationToken")) { DefaultValue = "default" }); | ||
|
|
||
| var continuation_type = opt.GetOutputName (method.Parameters [method.Parameters.Count - 1].Type); | ||
| var args = parameters.GetCall (opt); | ||
| if (args.Length > 0) | ||
| args += ", "; | ||
| args += $"global::Android.Runtime.Extensions.JavaCast<{continuation_type}> (__continuation)"; | ||
| var target = selfType != null ? "self." + method.AdjustedName : method.AdjustedName; | ||
| var invoke = $"__continuation => {target} ({args})"; |
For a function such as `@JvmName("renamed") fun original(count: Int)`,
kotlinc writes only the JVM name in the Kotlin metadata, not the
descriptor. `KotlinFunction.FromProtobuf()` then read string-table
entry 0 as `JvmSignature`, for example `xat/bytecode/tests/RenamedOnly;`.
XA4268 showed this text instead of the parameter types.
Set `JvmSignature` to `null` when the descriptor index is 0, as is
already done for the JVM name. `ConstructJvmSignature()` is then used.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Kotlin `@JvmInline value class` types are bound as a `readonly struct`
(`KotlinInlineClassStruct`) wrapping the underlying primitive. That only
worked where the JVM erases the value class to its primitive. Where the
JVM passes the boxed class instead, such as a nullable `Foo?`, the
generator treated the struct as a `Java.Lang.Object` peer and emitted
`GetObject<Foo>()` / `JNIEnv.ToLocalJniHandle (foo)`, which can't marshal
a struct.
class-parse now records the JNI signatures of the compiler-generated
`box-impl`, `unbox-impl`, and `constructor-impl` helpers of each value
class. They are written to `api.xml` as
`kotlin-inline-class-{box,unbox,constructor}-jni-signature`.
The generator uses them to:
* Add `Create (T)` (`constructor-impl`, which runs `init` validation),
`ToLocalJniHandle (Foo?)` (`box-impl`), and
`FromJniHandle (IntPtr, JniHandleOwnership)` (`unbox-impl`) to the
generated struct.
* Project boxed positions as `Foo?` and marshal them through these
helpers, using the new `KotlinInlineClassBoxedSymbol`.
* Project value classes used as generic type arguments (for example
`List<Foo>`) as `Java.Lang.Object`. `JavaList<T>` and related types
can't marshal a struct, so the elements stay boxed Java objects that
callers convert with `Foo.FromJniHandle`/`Foo.ToLocalJniHandle`.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Kotlin always emits box-impl(U)LFoo;, unbox-impl()U and constructor-impl(U)U for a value class, so there is no need to record them in class-parse and api.xml. Build them from the underlying JNI type in KotlinInlineClassStruct instead, and trim the test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add a Kotlin interface with a nullable value-class parameter and return to the fixture, and check that the callback marshals the return value with box-impl. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A boxed value class is already projected as `Foo?`, so the generated call sites must not add the null-forgiving operator when nullable reference types are on. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…juster class-parse output goes through JavaXmlApiImporter/Exporter before the generator reads it, and the adjuster dropped the value-class attributes (kotlin-inline-class*, managedName). So the struct projection and the unmangled names never reached a real binding build. Keep them in the PropertyBag, and run the generator end-to-end tests through the adjuster. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add an integration test that binds the real ui-unit-android 1.12.1
library and checks the generated C# for the Dp struct, a value-class
extension receiver, and unmangled lerp overloads.
The test found three bugs, fixed here:
* class-parse did not project an extension receiver (un Dp.x())
to the value-class type.
* class-parse did not apply Kotlin parameter names to value-class
parameters, because TypesMatch did not get the inline-class map.
* Java-to-C# callbacks passed the raw primitive and relied on an
implicit conversion, which is ambiguous when overloads take value
classes with different underlying types (Density.roundToPx(Dp) and
roundToPx(TextUnit)). Construct the struct explicitly. Also do not
emit ! for unboxed value-class structs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Address review feedback:
* Nested value classes went through BoundClass instead of the struct
writer, so nullable uses called missing helpers.
* A Java field of a value-class type kept GetObject<T> for a struct.
Project it like parameters and return values.
* Arrays of value classes used JNIEnv.NewArray/GetArray, which can't
marshal the struct. Skip these members.
* The struct helpers did not compile with MemorySafetyRulesVersion=2.
Use unsafe blocks with SAFETY comments, and build the ui-unit test
binding in that mode.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Address review feedback:
* R8 could remove box-impl, unbox-impl and constructor-impl, which the
value-class structs call by name over JNI. The generator now writes
-keep rules for value classes, and the binding adds them to
@(ProguardConfiguration), so they ship in the binding's .aar.
* A binding that references another binding could not find its
value-class structs. [Register] now allows structs (an acceptable
API change: AttributeUsage gets AttributeTargets.Struct). The struct
gets [Register ("jni/name", DoNotGenerateAcw=true)], and
CecilApiImporter imports a registered struct as a value class.
class-parse also marks value classes whose .class file is in another
library: only value classes and kotlin/* types erase to a JVM
primitive, and the generator projects them only when the referenced
struct has the same underlying type.
* JavaPeerScanner skips value types, so these structs are not added
to the trimmable typemap.
The ui-unit integration test now also binds TextIndent from ui-text
against the ui-unit binding, and checks the keep rule in the .aar.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Context: https://github.com/Redth/AndroidBindingsExperiments Kotlin functions and constructors with default parameter values are bound with every argument required, because the `$default` helpers and the `DefaultConstructorMarker` constructors that kotlinc emits are synthetic and are hidden. class-parse now records, for each public Kotlin function or constructor that has parameters with `DeclaresDefaultValue`, the exact JNI signature of its helper (`name$default (receiver?, params..., int masks..., Object)` on the declaring type or its `$DefaultImpls` class, or `<init> (params..., int masks..., DefaultConstructorMarker)`), as `kotlin-default-jni-signature`, `kotlin-default-owner`, and `kotlin-default-parameters` attributes. The helper must exist with the expected descriptor; otherwise nothing is recorded and the full-argument API is kept. Functions with extension receivers, continuations, or outer-class parameters are skipped, because they change the mask bit positions. Java.Interop.Tools.JavaTypeSystem keeps these attributes when it rewrites api.xml. The generator then creates one overload for each trailing parameter that can be omitted. The overload declares locals for the omitted parameters, sets one `int` mask bit for each of them (one mask for each 32 parameters), and calls the helper through JNI: * Class methods (instance and static) call the static `$default` helper with `this` as the receiver, so Kotlin still dispatches virtually. * Interface methods become default interface methods (only when `SupportDefaultInterfaceMethods` is on) and use a private `JniPeerMembers` for the helper owner. * Constructors are generated only for final classes: a derived managed type is created through its Java Callable Wrapper, which does not have the synthetic constructor. They have no `[Register]`. An overload is not generated when a member with the same name and parameter types already exists (for example, from `@JvmOverloads`). Defaults in the middle of the parameter list are not exposed. Validation: * `dotnet test tests/generator-Tests/generator-Tests.csproj`: 479 passed (new end-to-end test uses real kotlinc output through class-parse, JavaTypeSystem, and the generator) * `dotnet test tests/Xamarin.Android.Tools.Bytecode-Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj`: 132 passed, 2 skipped * `dotnet test tests/Java.Interop.Tools.JavaTypeSystem-Tests/Java.Interop.Tools.JavaTypeSystem-Tests.csproj`: 18 passed * `dotnet test tests/Java.Interop.Tools.Generator-Tests`: 18 passed * Full SDK build and on-device tests were not run. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove the redundant JavaTypeSystem round-trip test; the generator end-to-end test already runs class-parse output through JavaXmlApiImporter/JavaXmlApiExporter. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Rubber-duck review fixes: * Detect existing overloads by C# parameter types, using the generated members (string overloads, abstract interface members) and inherited methods. JNI types missed collections and inline classes that map to the same or different C# types. * Mark overloads such as ToString () with \ ew\ when they hide a System.Object member. * Skip protected constructors on sealed classes, and members with generated enum parameters or returns, whose helper clone loses the enum type. * Ignore empty kotlin-default-* attributes (for example, cleared in Metadata.xml). * Add the interface JniPeerMembers field only when an overload uses it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…verload datastore-core-jvm 1.2.1 has \class CorruptionException (message: String, cause: Throwable? = null)\. The test binds it with <AndroidMavenLibrary> (class-parse, api-xml-adjuster, generator) and checks that the binding has a CorruptionException (string) constructor that calls the DefaultConstructorMarker constructor. The library also has @jvmoverloads methods (DataStoreFactory.create), so the build also confirms that no duplicate overloads are generated. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…helper The rebased KotlinInlineClassEndToEndTests helper now runs class-parse output through the JavaTypeSystem adjuster and resolves types, so the test no longer does its own round trip. Add java.lang.String to the helper's reference API, which a real build gets from Mono.Android. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…thods class-parse records the Kotlin result type of suspend functions in api.xml (kotlin-suspend-return-type); the JavaTypeSystem adjuster passes it through. The generator emits an additive *Async(…, CancellationToken) method that calls the existing Continuation-based method through the new Android.Runtime.KotlinCoroutines helper. KotlinCoroutines creates the Continuation with java.lang.reflect.Proxy, so Mono.Android has no build-time Kotlin dependency. When kotlinx.coroutines is present, a Job is the coroutine context and the CancellationToken cancels it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…; add device test * Java.Lang.Throwable is not a Java.Lang.Object: cancel the Job with a null cause, and convert the Result.Failure exception by peer reference. * Add R8 keep rules for the Kotlin members that KotlinCoroutines finds by name, in all three default ProGuard configurations. * Add an MSBuildDeviceIntegration test that binds a Gradle module with Kotlin suspend functions and awaits the generated *Async methods. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Always cancel the Task when the token is canceled; with kotlinx, also cancel the Job. Not all suspend functions observe the Job. * Unregister (not Dispose) the token registration, so completion never waits for a running cancellation callback. * Treat a missing kotlinx Job member like a missing kotlinx. * Result types: skip inline classes (boxed here) and invalid or non-public types. * Skip methods with an explicit interface; don't emit empty interface extension classes for static-only suspend methods. * Add MethodParameterWriter.DefaultValue instead of a custom writer. * Tests: drop a duplicate XML test; run the device test once, in Release with R8, which covers the keep rules. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…sk methods datastore-preferences-core-jvm has real Kotlin suspend APIs. The test binds it with <AndroidMavenLibrary> and checks that PreferencesKt.edit gets a Task-returning EditAsync method. Version 1.2.1 matches the published NuGet packages for its dependencies. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jonathanpeppers
force-pushed
the
jonathanpeppers-kotlin-suspend-as-task
branch
from
November 16, 2026 22:43
e0feeef to
7b2b727
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Context: #13582
Note
This PR is part of a stack (#13577 → #13580 → #13581 → #13582 → this PR). It is stacked on #13582. Review only the commits in this layer.
Many modern Android libraries expose Kotlin
suspendfunctions. The JVM signature ofsuspend fun add(a: Int, b: Int): IntisObject add(int, int, Continuation). The binding generator emitsJava.Lang.Object Add (int a, int b, Kotlin.Coroutines.IContinuation p2), which cannot be used from C# without your ownContinuationimplementation.KotlinFunctionFlags.IsSuspendwas parsed, but nothing used it.Bindings now also get an additive
*Asyncmethod. The existingContinuation-based method does not change:Binding generation
suspendfunction askotlin-suspend-return-typeinapi.xml(for examplekotlin/Int,kotlin/String?; type parameters becomekotlin/Any?). The result type comes from Kotlin metadata, not from the erasedObjectreturn type. The api.xml adjuster passes the attribute through with the other Kotlin method attributes.Task(forkotlin/Unit), toTask<T>for strings, primitives (including nullable primitives), and public, valid bound types, and toTask<Java.Lang.Object>for all other types. Inline value classes stayJava.Lang.Object, because they are boxed in this position.*Asyncmethods. Interface instance methods get extension methods in the existing*Extensionsclass. Static interface methods get a wrapper on the interface. The generator skips overrides, explicit interface implementations, methods that already havegenerateAsyncWrapper, and names that are already in use.Runtime:
Android.Runtime.KotlinCoroutinesNew public API in
Mono.Android, called by the generated code:kotlin.coroutines.Continuationis ajava.lang.reflect.Proxywith a managedInvocationHandler, soMono.Androidhas no build-time dependency on Kotlin and no new package or Java sources are needed. Kotlin classes are found at run time through the app class loader.COROUTINE_SUSPENDEDreturn completes theTasklater, when Kotlin callsresumeWith. Other return values complete it immediately. Akotlin.Result$Failurebecomes the matching managed exception (for exampleJava.Lang.IllegalStateException). Results are converted with the existingJavaConvert.FromJavaObject<T>.Task. Whenkotlinx.coroutinesis in the app, the continuation context is a newkotlinx.coroutines.Job, and the token also callsJob.cancel, so cancellable Kotlin code (for exampledelay,withContext) stops. Withoutkotlinx.coroutines, the context isEmptyCoroutineContextand the Kotlin work continues.ClassNotFoundException: kotlin.coroutines.EmptyCoroutineContextbefore these rules were added.The alternative was a separate package with a Kotlin bridge built on
kotlinx.coroutines(as in the Redth/AndroidBindingsExperiments prototype). It would add a build-time Kotlin dependency and a new package, and it would requirekotlinx.coroutinesin every app.Validation
Standalone tests (
bin\Debug\dotnet\dotnet test):tests\Xamarin.Android.Tools.Bytecode-Tests: Passed 137, Skipped 2 (includes the newKotlinSuspendTestswith a Gradle-compiledSuspendFunctions.ktfixture).tests\Java.Interop.Tools.JavaTypeSystem-Tests: Passed 18.tests\generator-Tests: Passed 481 (includes the new end-to-endKotlinSuspendTests).Full SDK build (
dotnet-local.cmd build Microsoft.Android.slnx,-t:BuildExtraApiLevels,-t:PackDotNet), then:Passed 3/3.
KotlinSuspendFunctionsAsTasksbindsandroidx.datastore:datastore-preferences-core-jvm1.2.1 with<AndroidMavenLibrary/>and checks the generatedPreferencesKt.EditAsync. (Version 1.3.0 requiresdatastore-core-jvm1.3.0 exactly, and the newest NuGet packages are 1.2.1.1.)On-device (x86_64 API 36 emulator, CoreCLR):
suspendfunctions, bound into an app (the same code as the newMSBuildDeviceIntegrationtestKotlinSuspendTests.SuspendFunctionsAsTasks). Debug and Release with$(AndroidLinkTool)=r8both logsum=5 greeting=Hello, Kotlin nothing=True failure=boom canceled=True. This covers an asynchronous resume, a synchronous result, anullresult, a Kotlin exception, and cancellation throughkotlinx.coroutines.delay.PreferencesKt.EditAsynccalls and one canceled edit logcount=2 thread=DefaultDispatcher-worker-1 canceled=True. The transform runs on akotlinx.coroutinesDispatchers.IOworker, the second edit reads the stored value, and cancellation works.The
MSBuildDeviceIntegrationtest was not run through NUnit locally: on Windows its teardown runsadb kill-server, which disconnects other users of the shared host. The same project was built and run by hand. The test compiles against Kotlinkotlinx-coroutines-core:1.10.2from Maven (compile only); if the CI Maven mirror does not have it yet, seed it witheng/gradle/mirror-dependencies.ps1 -MavenArtifact.