From ca3f98e2020aa2f45cdb1947a79e3b2ed01eeaa7 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Thu, 18 Sep 2025 16:34:11 -0500 Subject: [PATCH 1/3] adding assets support --- src/androidbuild/apk.zig | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/androidbuild/apk.zig b/src/androidbuild/apk.zig index b60ef4f..22410ab 100644 --- a/src/androidbuild/apk.zig +++ b/src/androidbuild/apk.zig @@ -47,6 +47,7 @@ android_manifest: ?LazyPath, artifacts: std.ArrayListUnmanaged(*Step.Compile), java_files: std.ArrayListUnmanaged(LazyPath), resources: std.ArrayListUnmanaged(Resource), +assets: std.ArrayListUnmanaged(LazyPath), pub const Options = struct { /// ie. "35.0.0" @@ -92,6 +93,7 @@ pub fn create(sdk: *Sdk, options: Options) *Apk { .artifacts = .empty, .java_files = .empty, .resources = .empty, + .assets = .empty, }; return apk; } @@ -116,6 +118,13 @@ pub fn addResourceDirectory(apk: *Apk, dir: LazyPath) void { }) catch @panic("OOM"); } +/// Set the directory of your Android assets folder. +/// - assets/MyImage.png +pub fn addAssetsDirectory(apk: *Apk, dir: LazyPath) void { + const b = apk.b; + apk.assets.append(b.allocator, dir) catch @panic("OOM"); +} + /// Add artifact to the Android build, this should be a shared library (*.so) /// that targets x86, x86_64, aarch64, etc pub fn addArtifact(apk: *Apk, compile: *std.Build.Step.Compile) void { @@ -344,14 +353,12 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile { aapt2link.addArg("-o"); const resources_apk_file = aapt2link.addOutputFileArg("resources.apk"); - // TODO(jae): 2024-09-17 - // Add support for asset directories - // Additional directory - // aapt.step.dependOn(&resource_write_files.step); - // for (app_config.asset_directories) |dir| { - // make_unsigned_apk.addArg("-A"); // additional directory in which to find raw asset files - // make_unsigned_apk.addArg(sdk.b.pathFromRoot(dir)); - // } + for (apk.assets.items) |dir| { + aapt2link.addArg("-A"); // additional directory in which to find raw asset files + const val = dir.src_path.sub_path; + + aapt2link.addArg(val); + } // Add resource files for (apk.resources.items) |resource| { From a795a2ffeeda8664a4a2c04631ff0ecc2295aa5f Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Sun, 21 Sep 2025 22:43:15 -0500 Subject: [PATCH 2/3] going to tidy this up --- build.zig | 2 - .../android/assets/assets/hello_android.txt | 1 + .../minimal/android/assets/hello_android.txt | 1 + examples/minimal/build.zig | 1 + examples/minimal/src/android-bind.zig | 4 -- examples/sdl2/android/AndroidManifest.xml | 58 +------------------ src/android/android.zig | 4 -- src/androidbuild/apk.zig | 1 + 8 files changed, 6 insertions(+), 66 deletions(-) create mode 100644 examples/minimal/android/assets/assets/hello_android.txt create mode 100644 examples/minimal/android/assets/hello_android.txt diff --git a/build.zig b/build.zig index 4b092b3..4f11a31 100644 --- a/build.zig +++ b/build.zig @@ -1,8 +1,6 @@ const std = @import("std"); const androidbuild = @import("src/androidbuild/androidbuild.zig"); -// Expose Android build functionality for use in your build.zig - // TODO: rename tools.zig to Sdk.zig pub const Sdk = @import("src/androidbuild/tools.zig"); pub const Apk = @import("src/androidbuild/apk.zig"); diff --git a/examples/minimal/android/assets/assets/hello_android.txt b/examples/minimal/android/assets/assets/hello_android.txt new file mode 100644 index 0000000..190e8da --- /dev/null +++ b/examples/minimal/android/assets/assets/hello_android.txt @@ -0,0 +1 @@ +hello from android diff --git a/examples/minimal/android/assets/hello_android.txt b/examples/minimal/android/assets/hello_android.txt new file mode 100644 index 0000000..81741de --- /dev/null +++ b/examples/minimal/android/assets/hello_android.txt @@ -0,0 +1 @@ +hello android! diff --git a/examples/minimal/build.zig b/examples/minimal/build.zig index 3653b34..34e1856 100644 --- a/examples/minimal/build.zig +++ b/examples/minimal/build.zig @@ -27,6 +27,7 @@ pub fn build(b: *std.Build) void { apk.setKeyStore(key_store_file); apk.setAndroidManifest(b.path("android/AndroidManifest.xml")); apk.addResourceDirectory(b.path("android/res")); + apk.addAssetsDirectory(b.path("android/assets")); // Add Java files // - If you have 'android:hasCode="false"' in your AndroidManifest.xml then no Java files are required diff --git a/examples/minimal/src/android-bind.zig b/examples/minimal/src/android-bind.zig index 0fd96f5..4a956fe 100644 --- a/examples/minimal/src/android-bind.zig +++ b/examples/minimal/src/android-bind.zig @@ -1,7 +1,3 @@ -// TODO(jae): 2024-09-19 -// Consider just making this import from native C libraries. -// For now just wanted a basic example that compiles and runs on an Android emulator - const __builtin_va_list = extern struct { padding: u32, }; diff --git a/examples/sdl2/android/AndroidManifest.xml b/examples/sdl2/android/AndroidManifest.xml index 7274684..d876123 100644 --- a/examples/sdl2/android/AndroidManifest.xml +++ b/examples/sdl2/android/AndroidManifest.xml @@ -4,22 +4,11 @@ android:versionName="1.0" android:installLocation="auto" package="com.zig.sdl2"> - - - - - - - - @@ -29,50 +18,19 @@ - - - - - - - - - - - - - - - - + + - - - - - - - - - - - diff --git a/src/android/android.zig b/src/android/android.zig index 2f19ed2..07dda21 100644 --- a/src/android/android.zig +++ b/src/android/android.zig @@ -1,10 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -// TODO(jae): 2024-10-03 -// Consider exposing this in the future -// pub const builtin = android_builtin; - const android_builtin = struct { const ab = @import("android_builtin"); diff --git a/src/androidbuild/apk.zig b/src/androidbuild/apk.zig index 22410ab..5ae3b11 100644 --- a/src/androidbuild/apk.zig +++ b/src/androidbuild/apk.zig @@ -358,6 +358,7 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile { const val = dir.src_path.sub_path; aapt2link.addArg(val); + //aapt2link.addFileInput(dir); } // Add resource files From f3b52745aaf63a4133d6615a995a0b255ded5b4d Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Sun, 21 Sep 2025 22:43:47 -0500 Subject: [PATCH 3/3] going to clean up the commits --- examples/minimal/android/assets/assets/hello_android.txt | 1 - examples/minimal/android/assets/hello_android.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 examples/minimal/android/assets/assets/hello_android.txt delete mode 100644 examples/minimal/android/assets/hello_android.txt diff --git a/examples/minimal/android/assets/assets/hello_android.txt b/examples/minimal/android/assets/assets/hello_android.txt deleted file mode 100644 index 190e8da..0000000 --- a/examples/minimal/android/assets/assets/hello_android.txt +++ /dev/null @@ -1 +0,0 @@ -hello from android diff --git a/examples/minimal/android/assets/hello_android.txt b/examples/minimal/android/assets/hello_android.txt deleted file mode 100644 index 81741de..0000000 --- a/examples/minimal/android/assets/hello_android.txt +++ /dev/null @@ -1 +0,0 @@ -hello android!