diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 465b4fa..69d11ed 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 @@ -50,9 +54,50 @@ 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 + # 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 + # + - name: Setup Zig Nightly uses: mlugg/setup-zig@v1 with: diff --git a/examples/minimal/README.md b/examples/minimal/README.md index 39e1bd7..3af710b 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 -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 diff --git a/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java new file mode 100644 index 0000000..9cd7305 --- /dev/null +++ b/examples/sdl2/android/androidCrashTest/ZigSDLActivity.java @@ -0,0 +1,23 @@ +package com.zig.sdl2; // <- Your game package name + +import org.libsdl.app.SDLActivity; +import android.os.Bundle; +import android.util.AndroidRuntimeException; + +/** + * Used by ci.yml to make the application crash if an error occurs initializing your application. + * + * 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 + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (mBrokenLibraries) { + throw new AndroidRuntimeException("SDL Error, has broken libraries"); + } + } +} diff --git a/examples/sdl2/android/src/ZigSDLActivity.java b/examples/sdl2/android/src/ZigSDLActivity.java index 998ed62..9fc076e 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..6b5c327 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,16 @@ 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 { + // 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") }); + } // Add SDL2's Java files like SDL.java, SDLActivity.java, HIDDevice.java, etc const sdl_dep = b.dependency("sdl2", .{