[jnigen] Run Java GC using jcmd in tests (https://github.com/dart-lang/jnigen/issues/371)

meta: remove apk builds from windows minimal CI
diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml
index 7f6bcb3..5846f3c 100644
--- a/.github/workflows/test-package.yml
+++ b/.github/workflows/test-package.yml
@@ -248,12 +248,6 @@
       - run: Add-Content $env:GITHUB_PATH "$env:JAVA_HOME\bin\server"
       - run: dart pub get
       - run: dart run jnigen:setup
-      - name: build in_app_java APK
-        run: flutter build apk --target-platform=android-arm64
-        working-directory: ./pkgs/jnigen/example/in_app_java
-      - name: build notification_plugin example APK
-        run: flutter build apk --target-platform=android-arm64
-        working-directory: ./pkgs/jnigen/example/notification_plugin/example
       - name: Build summarizer
         run: dart run jnigen:setup
       - name: Generate runtime tests
diff --git a/pkgs/jnigen/test/descriptor_test.dart b/pkgs/jnigen/test/descriptor_test.dart
index 41ac58c..f1b9060 100644
--- a/pkgs/jnigen/test/descriptor_test.dart
+++ b/pkgs/jnigen/test/descriptor_test.dart
@@ -16,14 +16,13 @@
 
 void main() {
   checkLocallyBuiltDependencies();
-  test('Method descriptor generation', timeout: const Timeout.factor(3),
-      () async {
-    final configGetters = [
-      simple_package_test.getConfig,
-      kotlin_test.getConfig,
-      jackson_core_test.getConfig
-    ];
-    for (final getConfig in configGetters) {
+  for (final (name, getConfig) in [
+    ('simple_package', simple_package_test.getConfig),
+    ('kotlin', kotlin_test.getConfig),
+    ('jackson_core', jackson_core_test.getConfig),
+  ]) {
+    test('Method descriptor generation for $name',
+        timeout: const Timeout.factor(3), () async {
       final config = getConfig();
       config.summarizerOptions =
           SummarizerOptions(backend: SummarizerBackend.asm);
@@ -38,6 +37,6 @@
           expect(method.descriptor, method.accept(methodDescriptor));
         }
       }
-    }
-  });
+    });
+  }
 }
diff --git a/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart b/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
index 665a26d..cae9758 100644
--- a/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
+++ b/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
@@ -17,8 +17,16 @@
 const trillion = 1024 * 1024 * 1024 * 1024;
 
 void _runJavaGC() {
-  final system = Jni.findJClass('java/lang/System');
-  system.callStaticMethodByName<void>('gc', '()V', []);
+  final managementFactory =
+      Jni.findJClass('java/lang/management/ManagementFactory');
+  final bean = managementFactory.callStaticMethodByName<JObject>(
+      'getRuntimeMXBean', '()Ljava/lang/management/RuntimeMXBean;', []);
+  final pid = bean.callMethodByName<int>('getPid', '()J', []);
+  ProcessResult result;
+  do {
+    sleep(const Duration(milliseconds: 100));
+    result = Process.runSync('jcmd', [pid.toString(), 'GC.run']);
+  } while (result.exitCode != 0);
 }
 
 void registerTests(String groupName, TestRunnerCallback test) {