From 11583413d127a750b84d85ac154bad5f7a239f14 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sat, 29 Mar 2025 15:24:50 +1100 Subject: [PATCH 01/14] try this --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 465b4fa..7ef2da0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,10 @@ jobs: with: packages: 'tools platform-tools platforms;android-35 build-tools;35.0.0 ndk;29.0.13113456' + # + # Stable Zig Builds + # + - name: Setup Zig Stable (0.14.0) # note(jae): 2024-09-15 # Uses download mirror first as preferred by Zig Foundation @@ -53,6 +57,27 @@ jobs: run: zig build -Dandroid=true --verbose working-directory: examples/sdl2 + - name: Enable KVM (For Android emulation) + if: startsWith(matrix.os, 'ubuntu-') + 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 Minimal Example (Android Emulator) + uses: reactivecircus/android-emulator-runner@v2 + if: startsWith(matrix.os, 'ubuntu-') + working-directory: examples/minimal + with: + api-level: 34 + system-image-api-level: 34-ext9 + target: android-automotive + script: adb shell am start -n com.zig.minimal/android.app.NativeActivity + + # + # Nightly Zig Builds + # + - name: Setup Zig Nightly uses: mlugg/setup-zig@v1 with: From 941577326c452597575aeb3783e8867df44d1074 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sat, 29 Mar 2025 15:36:54 +1100 Subject: [PATCH 02/14] do --- .github/workflows/ci.yml | 4 ++-- examples/minimal/README.md | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ef2da0..6956de7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,14 +65,14 @@ jobs: sudo udevadm trigger --name-match=kvm - name: Run Minimal Example (Android Emulator) - uses: reactivecircus/android-emulator-runner@v2 if: startsWith(matrix.os, 'ubuntu-') - working-directory: examples/minimal + uses: reactivecircus/android-emulator-runner@v2 with: api-level: 34 system-image-api-level: 34-ext9 target: android-automotive script: adb shell am start -n com.zig.minimal/android.app.NativeActivity + working-directory: examples/minimal # # Nightly Zig Builds diff --git a/examples/minimal/README.md b/examples/minimal/README.md index 39e1bd7..53fd357 100644 --- a/examples/minimal/README.md +++ b/examples/minimal/README.md @@ -2,11 +2,12 @@ As of 2024-09-19, this is a thrown together, very quick copy-paste of the minimal example from the original [ZigAndroidTemplate](https://github.com/ikskuh/ZigAndroidTemplate/blob/master/examples/minimal/main.zig) repository. -### Build and install to test one target against a local emulator +### Build, install to test one target against a local emulator and run ```sh zig build -Dtarget=x86_64-linux-android adb install ./zig-out/bin/minimal.apk +adb shell am start -S -n com.zig.minimal/android.app.NativeActivity ``` ### Build and install for all supported Android targets From 2619d7b66fbe175b8ed646d54000261d4048750c Mon Sep 17 00:00:00 2001 From: Jae B Date: Sat, 29 Mar 2025 16:55:42 +1100 Subject: [PATCH 03/14] run --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6956de7..c9d0830 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: api-level: 34 system-image-api-level: 34-ext9 target: android-automotive - script: adb shell am start -n com.zig.minimal/android.app.NativeActivity + script: adb install ./zig-out/bin/minimal.apk && adb shell am start -n com.zig.minimal/android.app.NativeActivity working-directory: examples/minimal # From 4361ce05686f517af1867ff0f64dbbbbdd335f30 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sat, 29 Mar 2025 16:56:59 +1100 Subject: [PATCH 04/14] test --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9d0830..e4b1f01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,8 +69,8 @@ jobs: uses: reactivecircus/android-emulator-runner@v2 with: api-level: 34 - system-image-api-level: 34-ext9 - target: android-automotive + arch: x86_64 + profile: Nexus 6 script: adb install ./zig-out/bin/minimal.apk && adb shell am start -n com.zig.minimal/android.app.NativeActivity working-directory: examples/minimal From 2fc157f7d30cc3710bcc17b525b1100915cd3839 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 08:54:45 +1100 Subject: [PATCH 05/14] more work --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4b1f01..68614b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,16 @@ jobs: script: adb install ./zig-out/bin/minimal.apk && adb shell am start -n com.zig.minimal/android.app.NativeActivity working-directory: examples/minimal + - name: Run SDL2 Example (Android Emulator) + if: startsWith(matrix.os, 'ubuntu-') + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 34 + arch: x86_64 + profile: Nexus 6 + script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -n com.zig.sdl2/android.app.NativeActivity + working-directory: examples/sdl-zig-demo + # # Nightly Zig Builds # From 8d57e8e6fec49cc997aa5fbfe2d8a86e01dda470 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 08:59:01 +1100 Subject: [PATCH 06/14] fix path --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68614b0..0a78aea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: arch: x86_64 profile: Nexus 6 script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -n com.zig.sdl2/android.app.NativeActivity - working-directory: examples/sdl-zig-demo + working-directory: examples/sdl2 # # Nightly Zig Builds From 7cd2e4beb652a6ed53264869145773b5d44ee6f2 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 09:35:14 +1100 Subject: [PATCH 07/14] fix activity name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a78aea..05f7d63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,7 +81,7 @@ jobs: api-level: 34 arch: x86_64 profile: Nexus 6 - script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -n com.zig.sdl2/android.app.NativeActivity + script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -n com.zig.sdl2/ZigSDLActivity working-directory: examples/sdl2 # From 0bf187c0583ab0cd90b949b340f5bc49c5c80d0c Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 09:55:18 +1100 Subject: [PATCH 08/14] fix --- .github/workflows/ci.yml | 4 ++-- examples/minimal/README.md | 2 +- examples/sdl2/README.md | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05f7d63..5179a7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: api-level: 34 arch: x86_64 profile: Nexus 6 - script: adb install ./zig-out/bin/minimal.apk && adb shell am start -n com.zig.minimal/android.app.NativeActivity + script: adb install ./zig-out/bin/minimal.apk && adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity working-directory: examples/minimal - name: Run SDL2 Example (Android Emulator) @@ -81,7 +81,7 @@ jobs: api-level: 34 arch: x86_64 profile: Nexus 6 - script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -n com.zig.sdl2/ZigSDLActivity + script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity working-directory: examples/sdl2 # diff --git a/examples/minimal/README.md b/examples/minimal/README.md index 53fd357..3af710b 100644 --- a/examples/minimal/README.md +++ b/examples/minimal/README.md @@ -7,7 +7,7 @@ As of 2024-09-19, this is a thrown together, very quick copy-paste of the minima ```sh zig build -Dtarget=x86_64-linux-android adb install ./zig-out/bin/minimal.apk -adb shell am start -S -n com.zig.minimal/android.app.NativeActivity +adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity ``` ### Build and install for all supported Android targets diff --git a/examples/sdl2/README.md b/examples/sdl2/README.md index c4b7e07..1f66fbf 100644 --- a/examples/sdl2/README.md +++ b/examples/sdl2/README.md @@ -2,11 +2,12 @@ This is a copy-paste of [Andrew Kelly's SDL Zig Demo](https://github.com/andrewrk/sdl-zig-demo) but running on Android. The build is setup so you can also target your native operating system as well. -### Build and install to test one target against a local emulator +### Build, install to test one target against a local emulator and run ```sh zig build -Dtarget=x86_64-linux-android adb install ./zig-out/bin/sdl-zig-demo.apk +adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity ``` ### Build and install for all supported Android targets From 74238c06a037269f04954685376541d0b577f821 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 11:26:54 +1100 Subject: [PATCH 09/14] try this --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5179a7f..8556dfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,9 @@ jobs: api-level: 34 arch: x86_64 profile: Nexus 6 - script: adb install ./zig-out/bin/minimal.apk && adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity + script: | + adb install ./zig-out/bin/minimal.apk + adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity working-directory: examples/minimal - name: Run SDL2 Example (Android Emulator) @@ -81,7 +83,10 @@ jobs: api-level: 34 arch: x86_64 profile: Nexus 6 - script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity + #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity + script: | + adb install ./zig-out/bin/sdl-zig-demo.apk + adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 working-directory: examples/sdl2 # From 1ff78b8ca63b7861bdfe4c3a410480fcfc7692fb Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 11:48:57 +1100 Subject: [PATCH 10/14] disable CI --- .github/workflows/ci.yml | 69 ++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8556dfe..13eb7ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,37 +57,44 @@ jobs: run: zig build -Dandroid=true --verbose working-directory: examples/sdl2 - - name: Enable KVM (For Android emulation) - if: startsWith(matrix.os, 'ubuntu-') - 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 Minimal Example (Android Emulator) - if: startsWith(matrix.os, 'ubuntu-') - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 34 - arch: x86_64 - profile: Nexus 6 - script: | - adb install ./zig-out/bin/minimal.apk - adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity - working-directory: examples/minimal - - - name: Run SDL2 Example (Android Emulator) - if: startsWith(matrix.os, 'ubuntu-') - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 34 - arch: x86_64 - profile: Nexus 6 - #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity - script: | - adb install ./zig-out/bin/sdl-zig-demo.apk - adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 - working-directory: examples/sdl2 + # NOTE(jae): 2025-03-30 + # Attempted to run examples on Ubuntu OS but even though the SDL2 example + # gets obvious errors with a dialog box popping up, I can't easily detect if a failure occurred. + # + # If I hacked the onCreate of SDLActivity and just made it throw an exception instead of having a dialog box + # that would probably catch instantiation issues but not sure it's worth doing. + + # - name: Enable KVM (For Android emulation) + # if: startsWith(matrix.os, 'ubuntu-') + # 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 Minimal Example (Android Emulator) + # if: startsWith(matrix.os, 'ubuntu-') + # uses: reactivecircus/android-emulator-runner@v2 + # with: + # api-level: 34 + # arch: x86_64 + # profile: Nexus 6 + # script: | + # adb install ./zig-out/bin/minimal.apk + # adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity + # working-directory: examples/minimal + + # - name: Run SDL2 Example (Android Emulator) + # if: startsWith(matrix.os, 'ubuntu-') + # uses: reactivecircus/android-emulator-runner@v2 + # with: + # api-level: 34 + # arch: x86_64 + # profile: Nexus 6 + # #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity + # script: | + # adb install ./zig-out/bin/sdl-zig-demo.apk + # adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 + # working-directory: examples/sdl2 # # Nightly Zig Builds From 6ef69df2fcddb4a354784daa24571a8c923eaad7 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 11:55:08 +1100 Subject: [PATCH 11/14] do the work --- .github/workflows/ci.yml | 73 +++++++++---------- .../androidCrashTest/ZigSDLActivity.java | 21 ++++++ examples/sdl2/android/src/ZigSDLActivity.java | 11 --- examples/sdl2/build.zig | 8 +- 4 files changed, 62 insertions(+), 51 deletions(-) create mode 100644 examples/sdl2/android/androidCrashTest/ZigSDLActivity.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13eb7ad..6372dfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,47 +54,42 @@ jobs: working-directory: examples/minimal - name: Build SDL2 Example (Zig Stable) - run: zig build -Dandroid=true --verbose + run: | + zig build -Dandroid=true --verbose + zig build -Dandroid=true -Dcrash-on-exception --verbose working-directory: examples/sdl2 - # NOTE(jae): 2025-03-30 - # Attempted to run examples on Ubuntu OS but even though the SDL2 example - # gets obvious errors with a dialog box popping up, I can't easily detect if a failure occurred. - # - # If I hacked the onCreate of SDLActivity and just made it throw an exception instead of having a dialog box - # that would probably catch instantiation issues but not sure it's worth doing. - - # - name: Enable KVM (For Android emulation) - # if: startsWith(matrix.os, 'ubuntu-') - # 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 Minimal Example (Android Emulator) - # if: startsWith(matrix.os, 'ubuntu-') - # uses: reactivecircus/android-emulator-runner@v2 - # with: - # api-level: 34 - # arch: x86_64 - # profile: Nexus 6 - # script: | - # adb install ./zig-out/bin/minimal.apk - # adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity - # working-directory: examples/minimal - - # - name: Run SDL2 Example (Android Emulator) - # if: startsWith(matrix.os, 'ubuntu-') - # uses: reactivecircus/android-emulator-runner@v2 - # with: - # api-level: 34 - # arch: x86_64 - # profile: Nexus 6 - # #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity - # script: | - # adb install ./zig-out/bin/sdl-zig-demo.apk - # adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 - # working-directory: examples/sdl2 + - name: Enable KVM (For Android emulation) + if: startsWith(matrix.os, 'ubuntu-') + 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 Minimal Example (Android Emulator) + if: startsWith(matrix.os, 'ubuntu-') + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 34 + arch: x86_64 + profile: Nexus 6 + script: | + adb install ./zig-out/bin/minimal.apk + adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity + working-directory: examples/minimal + + - name: Run SDL2 Example (Android Emulator) + if: startsWith(matrix.os, 'ubuntu-') + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 34 + arch: x86_64 + profile: Nexus 6 + #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity + script: | + adb install ./zig-out/bin/sdl-zig-demo.apk + adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 + working-directory: examples/sdl2 # # Nightly Zig Builds diff --git a/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java new file mode 100644 index 0000000..b320dca --- /dev/null +++ b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java @@ -0,0 +1,21 @@ +package com.zig.sdl2; // <- Your game package name + +import org.libsdl.app.SDLActivity; +import android.os.Bundle; +import android.util.AndroidRuntimeException; + +/** + * A sample wrapper class that just calls SDLActivity + * + * Used for testing only to detect if it crashes + */ +public class ZigSDLActivity extends SDLActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (mBrokenLibraries) { + throw new AndroidRuntimeException("SDL Error, has broken libraries"); + } + } +} \ No newline at end of file diff --git a/examples/sdl2/android/src/ZigSDLActivity.java b/examples/sdl2/android/src/ZigSDLActivity.java index 998ed62..edc4a65 100644 --- a/examples/sdl2/android/src/ZigSDLActivity.java +++ b/examples/sdl2/android/src/ZigSDLActivity.java @@ -6,15 +6,4 @@ * A sample wrapper class that just calls SDLActivity */ public class ZigSDLActivity extends SDLActivity { - // @Override - // protected String[] getLibraries() { - // return new String[] { - // "SDL2", - // // "SDL2_image", - // // "SDL2_mixer", - // // "SDL2_net", - // // "SDL2_ttf", - // "main" - // }; - // } } \ No newline at end of file diff --git a/examples/sdl2/build.zig b/examples/sdl2/build.zig index b5a6450..0bed193 100644 --- a/examples/sdl2/build.zig +++ b/examples/sdl2/build.zig @@ -7,6 +7,8 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const android_targets = android.standardTargets(b, root_target); + const crash_on_exception = b.option(bool, "crash-on-exception", "if true then we'll use the activity from androidCrashTest folder") orelse false; + var root_target_single = [_]std.Build.ResolvedTarget{root_target}; const targets: []std.Build.ResolvedTarget = if (android_targets.len == 0) root_target_single[0..] @@ -40,7 +42,11 @@ pub fn build(b: *std.Build) void { apk.addResourceDirectory(b.path("android/res")); // Add Java files - apk.addJavaSourceFile(.{ .file = b.path("android/src/ZigSDLActivity.java") }); + if (!crash_on_exception) { + apk.addJavaSourceFile(.{ .file = b.path("android/src/ZigSDLActivity.java") }); + } else { + apk.addJavaSourceFile(.{ .file = b.path("android/androidCrashTest/ZigSDLActivity.java") }); + } // Add SDL2's Java files like SDL.java, SDLActivity.java, HIDDevice.java, etc const sdl_dep = b.dependency("sdl2", .{ From 84ac82c12328165b99bbf9f345e459f54d20c614 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 12:02:49 +1100 Subject: [PATCH 12/14] more work --- .github/workflows/ci.yml | 2 +- examples/sdl2/android/androidCrashTest/ZigSDLActivity.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6372dfb..55b95b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,7 +88,7 @@ jobs: #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity script: | adb install ./zig-out/bin/sdl-zig-demo.apk - adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 + adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 --throttle 1000 -v 2 working-directory: examples/sdl2 # diff --git a/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java index b320dca..4d5eb5e 100644 --- a/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java +++ b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java @@ -5,9 +5,11 @@ import android.util.AndroidRuntimeException; /** - * A sample wrapper class that just calls SDLActivity + * Used by ci.yml to make the application crash if an error occurs initializing your application. * - * Used for testing only to detect if it crashes + * This allows the following commands to catch crash errors on startup: + * - adb install ./zig-out/bin/sdl-zig-demo.apk + * - adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 */ public class ZigSDLActivity extends SDLActivity { @Override From 97f779d005662e9fef75062935f337dfcb0c84ed Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 12:16:50 +1100 Subject: [PATCH 13/14] do the work --- .github/workflows/ci.yml | 65 +++++++++++++++++++++------------------- examples/sdl2/build.zig | 5 ++++ 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55b95b6..69d11ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,37 +59,40 @@ jobs: zig build -Dandroid=true -Dcrash-on-exception --verbose working-directory: examples/sdl2 - - name: Enable KVM (For Android emulation) - if: startsWith(matrix.os, 'ubuntu-') - 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 Minimal Example (Android Emulator) - if: startsWith(matrix.os, 'ubuntu-') - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 34 - arch: x86_64 - profile: Nexus 6 - script: | - adb install ./zig-out/bin/minimal.apk - adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity - working-directory: examples/minimal - - - name: Run SDL2 Example (Android Emulator) - if: startsWith(matrix.os, 'ubuntu-') - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: 34 - arch: x86_64 - profile: Nexus 6 - #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity - script: | - adb install ./zig-out/bin/sdl-zig-demo.apk - adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 --throttle 1000 -v 2 - working-directory: examples/sdl2 + # TODO(jae): 2025-03-30 + # Need to figure out how to get 'adb shell monkey' to return an error code or be able to return an error code + # if the stdout of the command has 'Monkey aborted due to error.' + + # - name: Enable KVM (For Android emulation) + # if: startsWith(matrix.os, 'ubuntu-') + # 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 Minimal Example (Android Emulator) + # if: startsWith(matrix.os, 'ubuntu-') + # uses: reactivecircus/android-emulator-runner@v2 + # with: + # api-level: 34 + # arch: x86_64 + # profile: Nexus 6 + # script: | + # adb install ./zig-out/bin/minimal.apk + # adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity + # working-directory: examples/minimal + + # - name: Run SDL2 Example (Android Emulator) + # if: startsWith(matrix.os, 'ubuntu-') + # uses: reactivecircus/android-emulator-runner@v2 + # with: + # api-level: 34 + # arch: x86_64 + # profile: Nexus 6 + # script: | + # adb install ./zig-out/bin/sdl-zig-demo.apk + # adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 --throttle 1000 -v 2 + # working-directory: examples/sdl2 # # Nightly Zig Builds diff --git a/examples/sdl2/build.zig b/examples/sdl2/build.zig index 0bed193..6b5c327 100644 --- a/examples/sdl2/build.zig +++ b/examples/sdl2/build.zig @@ -45,6 +45,11 @@ pub fn build(b: *std.Build) void { if (!crash_on_exception) { apk.addJavaSourceFile(.{ .file = b.path("android/src/ZigSDLActivity.java") }); } else { + // This is used for testing in Github Actions, so that we can call "adb shell monkey" and trigger + // an error. + // - adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50 + // + // This alternate SDLActivity skips the nice dialog box you get when doing manual human testing. apk.addJavaSourceFile(.{ .file = b.path("android/androidCrashTest/ZigSDLActivity.java") }); } From de9a133623ec7c0217a603068fd3303aaedb5dd3 Mon Sep 17 00:00:00 2001 From: Jae B Date: Sun, 30 Mar 2025 12:56:15 +1100 Subject: [PATCH 14/14] more work --- examples/sdl2/android/androidCrashTest/ZigSDLActivity.java | 2 +- examples/sdl2/android/src/ZigSDLActivity.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java index 4d5eb5e..9cd7305 100644 --- a/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java +++ b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java @@ -20,4 +20,4 @@ protected void onCreate(Bundle savedInstanceState) { throw new AndroidRuntimeException("SDL Error, has broken libraries"); } } -} \ No newline at end of file +} diff --git a/examples/sdl2/android/src/ZigSDLActivity.java b/examples/sdl2/android/src/ZigSDLActivity.java index edc4a65..9fc076e 100644 --- a/examples/sdl2/android/src/ZigSDLActivity.java +++ b/examples/sdl2/android/src/ZigSDLActivity.java @@ -6,4 +6,4 @@ * A sample wrapper class that just calls SDLActivity */ public class ZigSDLActivity extends SDLActivity { -} \ No newline at end of file +}