Skip to content

Commit 6ef69df

Browse files
committed
do the work
1 parent 1ff78b8 commit 6ef69df

File tree

4 files changed

+62
-51
lines changed

4 files changed

+62
-51
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,47 +54,42 @@ jobs:
5454
working-directory: examples/minimal
5555

5656
- name: Build SDL2 Example (Zig Stable)
57-
run: zig build -Dandroid=true --verbose
57+
run: |
58+
zig build -Dandroid=true --verbose
59+
zig build -Dandroid=true -Dcrash-on-exception --verbose
5860
working-directory: examples/sdl2
5961

60-
# NOTE(jae): 2025-03-30
61-
# Attempted to run examples on Ubuntu OS but even though the SDL2 example
62-
# gets obvious errors with a dialog box popping up, I can't easily detect if a failure occurred.
63-
#
64-
# If I hacked the onCreate of SDLActivity and just made it throw an exception instead of having a dialog box
65-
# that would probably catch instantiation issues but not sure it's worth doing.
66-
67-
# - name: Enable KVM (For Android emulation)
68-
# if: startsWith(matrix.os, 'ubuntu-')
69-
# run: |
70-
# echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
71-
# sudo udevadm control --reload-rules
72-
# sudo udevadm trigger --name-match=kvm
73-
74-
# - name: Run Minimal Example (Android Emulator)
75-
# if: startsWith(matrix.os, 'ubuntu-')
76-
# uses: reactivecircus/android-emulator-runner@v2
77-
# with:
78-
# api-level: 34
79-
# arch: x86_64
80-
# profile: Nexus 6
81-
# script: |
82-
# adb install ./zig-out/bin/minimal.apk
83-
# adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity
84-
# working-directory: examples/minimal
85-
86-
# - name: Run SDL2 Example (Android Emulator)
87-
# if: startsWith(matrix.os, 'ubuntu-')
88-
# uses: reactivecircus/android-emulator-runner@v2
89-
# with:
90-
# api-level: 34
91-
# arch: x86_64
92-
# profile: Nexus 6
93-
# #script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity
94-
# script: |
95-
# adb install ./zig-out/bin/sdl-zig-demo.apk
96-
# adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50
97-
# working-directory: examples/sdl2
62+
- name: Enable KVM (For Android emulation)
63+
if: startsWith(matrix.os, 'ubuntu-')
64+
run: |
65+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
66+
sudo udevadm control --reload-rules
67+
sudo udevadm trigger --name-match=kvm
68+
69+
- name: Run Minimal Example (Android Emulator)
70+
if: startsWith(matrix.os, 'ubuntu-')
71+
uses: reactivecircus/android-emulator-runner@v2
72+
with:
73+
api-level: 34
74+
arch: x86_64
75+
profile: Nexus 6
76+
script: |
77+
adb install ./zig-out/bin/minimal.apk
78+
adb shell am start -S -W -n com.zig.minimal/android.app.NativeActivity
79+
working-directory: examples/minimal
80+
81+
- name: Run SDL2 Example (Android Emulator)
82+
if: startsWith(matrix.os, 'ubuntu-')
83+
uses: reactivecircus/android-emulator-runner@v2
84+
with:
85+
api-level: 34
86+
arch: x86_64
87+
profile: Nexus 6
88+
#script: adb install ./zig-out/bin/sdl-zig-demo.apk && adb shell am start -S -W -n com.zig.sdl2/com.zig.sdl2.ZigSDLActivity
89+
script: |
90+
adb install ./zig-out/bin/sdl-zig-demo.apk
91+
adb shell monkey --kill-process-after-error --monitor-native-crashes --pct-touch 100 -p com.zig.sdl2 -v 50
92+
working-directory: examples/sdl2
9893

9994
#
10095
# Nightly Zig Builds
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.zig.sdl2; // <- Your game package name
2+
3+
import org.libsdl.app.SDLActivity;
4+
import android.os.Bundle;
5+
import android.util.AndroidRuntimeException;
6+
7+
/**
8+
* A sample wrapper class that just calls SDLActivity
9+
*
10+
* Used for testing only to detect if it crashes
11+
*/
12+
public class ZigSDLActivity extends SDLActivity {
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
17+
if (mBrokenLibraries) {
18+
throw new AndroidRuntimeException("SDL Error, has broken libraries");
19+
}
20+
}
21+
}

examples/sdl2/android/src/ZigSDLActivity.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,4 @@
66
* A sample wrapper class that just calls SDLActivity
77
*/
88
public class ZigSDLActivity extends SDLActivity {
9-
// @Override
10-
// protected String[] getLibraries() {
11-
// return new String[] {
12-
// "SDL2",
13-
// // "SDL2_image",
14-
// // "SDL2_mixer",
15-
// // "SDL2_net",
16-
// // "SDL2_ttf",
17-
// "main"
18-
// };
19-
// }
209
}

examples/sdl2/build.zig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub fn build(b: *std.Build) void {
77
const optimize = b.standardOptimizeOption(.{});
88
const android_targets = android.standardTargets(b, root_target);
99

10+
const crash_on_exception = b.option(bool, "crash-on-exception", "if true then we'll use the activity from androidCrashTest folder") orelse false;
11+
1012
var root_target_single = [_]std.Build.ResolvedTarget{root_target};
1113
const targets: []std.Build.ResolvedTarget = if (android_targets.len == 0)
1214
root_target_single[0..]
@@ -40,7 +42,11 @@ pub fn build(b: *std.Build) void {
4042
apk.addResourceDirectory(b.path("android/res"));
4143

4244
// Add Java files
43-
apk.addJavaSourceFile(.{ .file = b.path("android/src/ZigSDLActivity.java") });
45+
if (!crash_on_exception) {
46+
apk.addJavaSourceFile(.{ .file = b.path("android/src/ZigSDLActivity.java") });
47+
} else {
48+
apk.addJavaSourceFile(.{ .file = b.path("android/androidCrashTest/ZigSDLActivity.java") });
49+
}
4450

4551
// Add SDL2's Java files like SDL.java, SDLActivity.java, HIDDevice.java, etc
4652
const sdl_dep = b.dependency("sdl2", .{

0 commit comments

Comments
 (0)