Skip to content
Merged
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ pub fn build(b: *std.Build) !void {

## Installation

Add the following to your build.zig.zon file and run `zig build`.
Option A. Install with package manager
```sh
zig fetch --save https://github.com/silbinarywolf/zig-android-sdk/archive/REPLACE_WITH_WANTED_COMMIT.tar.gz"
```

Option B. Copy-paste the dependency into your project directly and put in a `third-party` folder. This is recommended if you want to easily hack on it or tweak it.
```zig
.{
.name = .yourzigproject,
.dependencies = .{
.android = .{
.path = "https://github.com/silbinarywolf/zig-android-sdk/archive/REPLACE_WITH_WANTED_COMMIT.tar.gz",
// .hash = REPLACE_WITH_HASH_FROM_BUILD_ERROR
.path = "third-party/zig-android-sdk",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = .android,
.version = "0.1.0",
.version = "0.2.0",
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
14 changes: 12 additions & 2 deletions src/androidbuild/apk.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const androidbuild = @import("androidbuild.zig");
const Sdk = @import("tools.zig");
const BuiltinOptionsUpdate = @import("builtin_options_update.zig");
Expand Down Expand Up @@ -394,7 +395,11 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile {
});
aapt2packagename.setName(runNameContext("aapt2 dump packagename"));
aapt2packagename.addFileArg(resources_apk);
break :blk aapt2packagename.captureStdOut();
const aapt2_package_name_file = if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
aapt2packagename.captureStdOut()
else
aapt2packagename.captureStdOut(.{});
break :blk aapt2_package_name_file;
};

const android_builtin = blk: {
Expand Down Expand Up @@ -770,7 +775,7 @@ fn updateLinkObjects(apk: *Apk, root_artifact: *Step.Compile, so_dir: []const u8
// Update libraries linked to this library
apk.updateLinkObjects(artifact, so_dir, raw_top_level_apk_files);

// Apply workaround for Zig 0.14.0
// Apply workaround for Zig 0.14.0 and Zig 0.15.X
apk.applyLibLinkCppWorkaroundIssue19(artifact);
},
else => continue,
Expand Down Expand Up @@ -806,6 +811,11 @@ fn applyLibLinkCppWorkaroundIssue19(apk: *Apk, artifact: *Step.Compile) void {

artifact.root_module.addLibraryPath(libcppabi_dir);

// NOTE(jae): 2025-11-18
// Due to Android include files not being provided by Zig, we should provide them if the library is linking against C++
// This resolves an issue where if you are trying to build the openxr_loader C++ code from source, it can't find standard library includes like <string> or <algorithm>
artifact.addIncludePath(.{ .cwd_relative = b.fmt("{s}/usr/include/c++/v1", .{apk.ndk.sysroot_path}) });

if (artifact.root_module.link_libcpp == true) {
// NOTE(jae): 2025-04-06
// Don't explicitly linkLibCpp
Expand Down
5 changes: 4 additions & 1 deletion src/androidbuild/tools.zig
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ pub fn createKeyStore(sdk: *const Sdk, options: CreateKey) KeyStore {
// ignore stderr, it just gives you an output like:
// "Generating 4,096 bit RSA key pair and self-signed certificate (SHA384withRSA) with a validity of 10,000 days
// for: CN=example.com, OU=ID, O=Example, L=Doe, ST=Jane, C=GB"
_ = keytool.captureStdErr();
_ = if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
keytool.captureStdErr()
else
keytool.captureStdErr(.{});
return .{
.file = keystore_file,
.password = options.password,
Expand Down
Loading