Testing currently works on Android by cross-compiling the test runner executable with the Swift SDK for Android, copying the binary along with any dependent shared object files (plus any resources the tests require) over to an Android emulator or device, and then just running the executable as a command-line tool using adb. This is how testing is performed by the GitHub swift-android-action, the swiftlang/github-workflows, and with the skip android test command. They all do the same thing in slightly different ways. There are some quirks (like having to re-run the test executable twice, once for XCTest and once for Testing), but overall it works fine.
But a command-line executable isn't a real "app", which means it doesn't have any ambient Java environment. This means that you can't access any of the Android Java SDK, or even much of the NDK (because many NDK libraries, despite being C or C++, still need to be initialized from an Android Java Context, like AAssetManager_fromJava and ANativeWindow_fromSurface). This severely limits what can be tested when it comes to integration with the Android platform.
So we want a way to package up the tests such that they can be executed in the context of an actual .apk that is launched on an emulator or device. Gradle has support for this through their "instrumentation testing", and it is how skip test (not to be confused with skip android test) works with transpiled test cases. What is missing is a way to actually invoke the XCTest/Swift Testing tests from an .apk, and that will require building and bundling the tests differently.
I raised this last May at Building tests as a dynamic library rather than an executable. What we need is a way to build the tests as a shared library rather than as a command-line executable, and then host the tests within an app, just like iOS testing is done from Xcode. I think what we need is the ability to output TestProductStyle.loadableBundle for non-Darwin platforms. Maybe @dschaefer2 or @grynspan knows? Then we need to figure out how to call into the tests from Java and process the output, something that @madsodgaard and @ktoso might help with. Then we need a nice way to build, package, and run them, either with a separate harness like skip android test, or via a SwiftPM Command Plugin, or by baking support for it right into SwiftPM itself.
This project cuts across different areas and workgroups: Testing, Java, SwiftPM, and Android. Is there precedent for an ephemeral "task force" workgroup to tackle interdisciplinary projects like this? Might there be interest in forming one and having a call in a couple of weeks?