Skip to content

Commit bdf0f1b

Browse files
committed
adding assets support
1 parent 4758c1a commit bdf0f1b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/androidbuild/apk.zig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ android_manifest: ?LazyPath,
4747
artifacts: std.ArrayListUnmanaged(*Step.Compile),
4848
java_files: std.ArrayListUnmanaged(LazyPath),
4949
resources: std.ArrayListUnmanaged(Resource),
50+
assets: std.ArrayListUnmanaged(LazyPath),
5051

5152
pub const Options = struct {
5253
/// ie. "35.0.0"
@@ -92,6 +93,7 @@ pub fn create(sdk: *Sdk, options: Options) *Apk {
9293
.artifacts = .empty,
9394
.java_files = .empty,
9495
.resources = .empty,
96+
.assets = .empty,
9597
};
9698
return apk;
9799
}
@@ -116,6 +118,13 @@ pub fn addResourceDirectory(apk: *Apk, dir: LazyPath) void {
116118
}) catch @panic("OOM");
117119
}
118120

121+
/// Set the directory of your Android assets folder.
122+
/// - assets/MyImage.png
123+
pub fn addAssetsDirectory(apk: *Apk, dir: LazyPath) void {
124+
const b = apk.b;
125+
apk.assets.append(b.allocator, dir) catch @panic("OOM");
126+
}
127+
119128
/// Add artifact to the Android build, this should be a shared library (*.so)
120129
/// that targets x86, x86_64, aarch64, etc
121130
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 {
344353
aapt2link.addArg("-o");
345354
const resources_apk_file = aapt2link.addOutputFileArg("resources.apk");
346355

347-
// TODO(jae): 2024-09-17
348-
// Add support for asset directories
349-
// Additional directory
350-
// aapt.step.dependOn(&resource_write_files.step);
351-
// for (app_config.asset_directories) |dir| {
352-
// make_unsigned_apk.addArg("-A"); // additional directory in which to find raw asset files
353-
// make_unsigned_apk.addArg(sdk.b.pathFromRoot(dir));
354-
// }
356+
for (apk.assets.items) |dir| {
357+
aapt2link.addArg("-A"); // additional directory in which to find raw asset files
358+
const val = dir.src_path.sub_path;
359+
360+
aapt2link.addArg(val);
361+
}
355362

356363
// Add resource files
357364
for (apk.resources.items) |resource| {

0 commit comments

Comments
 (0)