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/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 b60ef4f..5ae3b11 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,13 @@ 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); + //aapt2link.addFileInput(dir); + } // Add resource files for (apk.resources.items) |resource| {