Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/minimal/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub fn build(b: *std.Build) void {
apk.setAndroidManifest(b.path("android/AndroidManifest.xml"));
apk.addResourceDirectory(b.path("android/res"));

// Assets support - put your textures and sounds here, not in the resources:
// apk.addAssetDirectory(b.path("android/assets"));

// Add Java files
// - If you have 'android:hasCode="false"' in your AndroidManifest.xml then no Java files are required
// see: https://developer.android.com/ndk/samples/sample_na
Expand Down
28 changes: 20 additions & 8 deletions src/androidbuild/apk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ android_manifest: ?LazyPath,
artifacts: std.ArrayListUnmanaged(*Step.Compile),
java_files: std.ArrayListUnmanaged(LazyPath),
resources: std.ArrayListUnmanaged(Resource),
assets: std.ArrayListUnmanaged(Resource),

pub const Options = struct {
/// ie. "35.0.0"
Expand Down Expand Up @@ -93,6 +94,7 @@ pub fn create(sdk: *Sdk, options: Options) *Apk {
.artifacts = .empty,
.java_files = .empty,
.resources = .empty,
.assets = .empty
};
return apk;
}
Expand All @@ -117,6 +119,15 @@ pub fn addResourceDirectory(apk: *Apk, dir: LazyPath) void {
}) catch @panic("OOM");
}

pub fn addAssetDirectory(apk: *Apk, dir: LazyPath) void {
const b = apk.b;
apk.assets.append(b.allocator, Resource{
.directory = .{
.source = 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 {
Expand Down Expand Up @@ -345,14 +356,15 @@ 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));
// }
// Add assets
for (apk.assets.items) |asset| {
switch (asset) {
.directory => |asset_dir| {
aapt2link.addArg("-A");
aapt2link.addDirectoryArg(asset_dir.source);
}
}
}

// Add resource files
for (apk.resources.items) |resource| {
Expand Down