Skip to content

[jnigen] Add Android emulator to CI #2206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/jnigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ jobs:
path-to-lcov: ./pkgs/jnigen/coverage/lcov.info
if: ${{ matrix.sdk == 'stable' }}

test_jnigen_android:
needs: [analyze_jnigen]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./pkgs/jnigen/android_test_runner
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: subosito/flutter-action@e938fdf56512cc96ef2f93601a5a40bde3801046
with:
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- name: Install dependencies
run: dart pub get
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run tests
uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d
with:
api-level: 26
arch: x86_64
script: flutter test --timeout=1200s integration_test/
working-directory: ./pkgs/jnigen/android_test_runner
analyze_jni:
runs-on: ubuntu-latest
defaults:
Expand Down
20 changes: 10 additions & 10 deletions pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ void registerTests(String groupName, TestRunnerCallback test) {
final manyPrimitives = await manyPrimitivesResult.future;
expect(manyPrimitives, -1 + 3 + 3.14.toInt() + 1);

// Running garbage collection does not work on Android. Skipping this
// test on Android.
// Currently we have one implementation of the interface.
expect(MyInterface.$impls, hasLength(1), skip: Platform.isAndroid);
myInterface.release();
if (!Platform.isAndroid) {
// Running garbage collection does not work on Android. Skipping this
// test for android.
_runJavaGC();
await _waitUntil(() => MyInterface.$impls.isEmpty);
expect(MyInterface.$impls, isEmpty);
Expand Down Expand Up @@ -691,12 +691,12 @@ void registerTests(String groupName, TestRunnerCallback test) {
);
expect(myInterface.manyPrimitives(1, true, 3, 4), 42);

// Running garbage collection does not work on Android. Skipping this
// test on Android.
expect(MyInterface.$impls, hasLength(1), skip: Platform.isAndroid);
expect(MyRunnable.$impls, hasLength(1), skip: Platform.isAndroid);
myInterface.release();
if (!Platform.isAndroid) {
// Running garbage collection does not work on Android. Skipping this
// test for android.
_runJavaGC();
await _waitUntil(() => MyInterface.$impls.isEmpty);
// Since the interface is now deleted, the cleaner must signal to Dart
Expand Down Expand Up @@ -742,12 +742,12 @@ void registerTests(String groupName, TestRunnerCallback test) {
// listener, it will work.
runner.runOnAnotherThreadAndJoin();
await completer.future;
expect(MyRunnable.$impls, hasLength(1));
// Running garbage collection does not work on Android. Skipping
// this test on Android.
expect(MyRunnable.$impls, hasLength(1), skip: Platform.isAndroid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some documentation why this needs to be skipped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are below it, will move it up.

runnable.release();
runner.release();
if (!Platform.isAndroid) {
// Running garbage collection does not work on Android. Skipping
// this test for android.
_runJavaGC();
await _waitUntil(() => MyInterface.$impls.isEmpty);
// Since the interface is now deleted, the cleaner must signal to
Expand All @@ -762,11 +762,11 @@ void registerTests(String groupName, TestRunnerCallback test) {
expect(runnable != runnable, false);
expect(runnable.hashCode, runnable.hashCode);
expect(runnable.toString(), runnable.toString());
expect(MyRunnable.$impls, hasLength(1));
// Running garbage collection does not work on Android. Skipping
// this test on Android.
expect(MyRunnable.$impls, hasLength(1), skip: Platform.isAndroid);
runnable.release();
if (!Platform.isAndroid) {
// Running garbage collection does not work on Android. Skipping
// this test for android.
_runJavaGC();
await _waitUntil(() => MyInterface.$impls.isEmpty);
expect(MyRunnable.$impls, isEmpty);
Expand Down
Loading