Skip to content

Commit bb698e2

Browse files
committed
more fixes
1 parent 897f3d4 commit bb698e2

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

examples/minimal/build.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ pub fn build(b: *std.Build) void {
1414
else
1515
android_targets;
1616

17-
const android_sdk = android.Sdk.create(b, .{});
1817
const android_apk: ?*android.Apk = blk: {
1918
if (android_targets.len == 0) break :blk null;
2019

20+
const android_sdk = android.Sdk.create(b, .{});
2121
const apk = android_sdk.createApk(.{
2222
.api_level = .android15,
2323
.build_tools_version = "35.0.1",
@@ -82,6 +82,7 @@ pub fn build(b: *std.Build) void {
8282
const installed_apk = apk.addInstallApk();
8383
b.getInstallStep().dependOn(&installed_apk.step);
8484

85+
const android_sdk = apk.sdk;
8586
const run_step = b.step("run", "Install and run the application on an Android device");
8687
const adb_install = android_sdk.addAdbInstall(installed_apk.source);
8788
const adb_start = android_sdk.addAdbStart("com.zig.minimal/android.app.NativeActivity");

examples/raylib/build.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ pub fn build(b: *std.Build) void {
1414
else
1515
android_targets;
1616

17-
const android_sdk = android.Sdk.create(b, .{});
1817
const android_apk: ?*android.Apk = blk: {
19-
if (android_targets.len == 0) {
20-
break :blk null;
21-
}
18+
if (android_targets.len == 0) break :blk null;
19+
20+
const android_sdk = android.Sdk.create(b, .{});
2221
const apk = android_sdk.createApk(.{
2322
.api_level = .android10,
2423
.build_tools_version = "35.0.1",
@@ -91,6 +90,7 @@ pub fn build(b: *std.Build) void {
9190
const installed_apk = apk.addInstallApk();
9291
b.getInstallStep().dependOn(&installed_apk.step);
9392

93+
const android_sdk = apk.sdk;
9494
const run_step = b.step("run", "Install and run the application on an Android device");
9595
const adb_install = android_sdk.addAdbInstall(installed_apk.source);
9696
const adb_start = android_sdk.addAdbStart("com.zig.raylib/android.app.NativeActivity");

examples/sdl2/build.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ pub fn build(b: *std.Build) void {
1515
else
1616
android_targets;
1717

18-
const android_sdk = android.Sdk.create(b, .{});
1918
const android_apk: ?*android.Apk = blk: {
20-
if (android_targets.len == 0) {
21-
break :blk null;
22-
}
19+
if (android_targets.len == 0) break :blk null;
20+
21+
const android_sdk = android.Sdk.create(b, .{});
2322
const apk = android_sdk.createApk(.{
2423
.api_level = .android15,
2524
.build_tools_version = "35.0.1",
@@ -135,6 +134,7 @@ pub fn build(b: *std.Build) void {
135134
const installed_apk = apk.addInstallApk();
136135
b.getInstallStep().dependOn(&installed_apk.step);
137136

137+
const android_sdk = apk.sdk;
138138
const run_step = b.step("run", "Install and run the application on an Android device");
139139
const adb_install = android_sdk.addAdbInstall(installed_apk.source);
140140
const adb_start = android_sdk.addAdbStart("com.zig.sdl2/com.zig.sdl2.ZigSDLActivity");

src/androidbuild/apk.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const std = @import("std");
22
const androidbuild = @import("androidbuild.zig");
3-
const Tools = @import("tools.zig");
3+
const Sdk = @import("tools.zig");
44
const BuiltinOptionsUpdate = @import("builtin_options_update.zig");
55

66
const Ndk = @import("Ndk.zig");
77
const BuildTools = @import("BuildTools.zig");
88
const D8Glob = @import("d8glob.zig");
99

10-
const KeyStore = Tools.KeyStore;
10+
const KeyStore = Sdk.KeyStore;
1111
const ApiLevel = androidbuild.ApiLevel;
1212
const getAndroidTriple = androidbuild.getAndroidTriple;
1313
const runNameContext = androidbuild.runNameContext;
@@ -32,7 +32,7 @@ pub const Resource = union(enum) {
3232
};
3333

3434
b: *std.Build,
35-
tools: *Tools,
35+
sdk: *Sdk,
3636
/// Path to Native Development Kit, this includes various C-code headers, libraries, and more.
3737
/// ie. $ANDROID_HOME/ndk/29.0.13113456
3838
ndk: Ndk,
@@ -57,17 +57,17 @@ pub const Options = struct {
5757
api_level: ApiLevel,
5858
};
5959

60-
pub fn create(tools: *Tools, options: Options) *Apk {
61-
const b = tools.b;
60+
pub fn create(sdk: *Sdk, options: Options) *Apk {
61+
const b = sdk.b;
6262

6363
var errors = std.ArrayList([]const u8).init(b.allocator);
6464
defer errors.deinit();
6565

66-
const build_tools = BuildTools.init(b, tools.android_sdk_path, options.build_tools_version, &errors) catch |err| switch (err) {
66+
const build_tools = BuildTools.init(b, sdk.android_sdk_path, options.build_tools_version, &errors) catch |err| switch (err) {
6767
error.BuildToolFailed => BuildTools.empty, // fallthruogh and print all errors below
6868
error.OutOfMemory => @panic("OOM"),
6969
};
70-
const ndk = Ndk.init(b, tools.android_sdk_path, options.ndk_version, &errors) catch |err| switch (err) {
70+
const ndk = Ndk.init(b, sdk.android_sdk_path, options.ndk_version, &errors) catch |err| switch (err) {
7171
error.NdkFailed => Ndk.empty, // fallthrough and print all errors below
7272
error.OutOfMemory => @panic("OOM"),
7373
};
@@ -79,7 +79,7 @@ pub fn create(tools: *Tools, options: Options) *Apk {
7979
const apk: *Apk = b.allocator.create(Apk) catch @panic("OOM");
8080
apk.* = .{
8181
.b = b,
82-
.tools = tools,
82+
.sdk = sdk,
8383
.ndk = ndk,
8484
.build_tools = build_tools,
8585
.api_level = options.api_level,
@@ -180,7 +180,7 @@ fn addLibraryPaths(apk: *Apk, module: *std.Build.Module) void {
180180
// ie. $ANDROID_HOME/ndk/{ndk_version}/sources/android/cpufeatures
181181
if (target.result.cpu.arch == .arm) {
182182
module.addIncludePath(.{
183-
.cwd_relative = b.fmt("{s}/ndk/{s}/sources/android/cpufeatures", .{ apk.tools.android_sdk_path, apk.ndk.version }),
183+
.cwd_relative = b.fmt("{s}/ndk/{s}/sources/android/cpufeatures", .{ apk.sdk.android_sdk_path, apk.ndk.version }),
184184
});
185185
}
186186

@@ -281,7 +281,7 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile {
281281

282282
// ie. "$ANDROID_HOME/Sdk/platforms/android-{api_level}/android.jar"
283283
const root_jar = b.pathResolve(&[_][]const u8{
284-
apk.tools.android_sdk_path,
284+
apk.sdk.android_sdk_path,
285285
"platforms",
286286
b.fmt("android-{d}", .{@intFromEnum(apk.api_level)}),
287287
"android.jar",
@@ -503,7 +503,7 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile {
503503
if (apk.java_files.items.len > 0) {
504504
// https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html
505505
const javac_cmd = b.addSystemCommand(&[_][]const u8{
506-
apk.tools.java_tools.javac,
506+
apk.sdk.java_tools.javac,
507507
// NOTE(jae): 2024-09-22
508508
// Force encoding to be "utf8", this fixes the following error occuring in Windows:
509509
// error: unmappable character (0x8F) for encoding windows-1252
@@ -557,7 +557,7 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile {
557557
// See: https://musteresel.github.io/posts/2019/07/build-android-app-bundle-on-command-line.html
558558
{
559559
const jar = b.addSystemCommand(&[_][]const u8{
560-
apk.tools.java_tools.jar,
560+
apk.sdk.java_tools.jar,
561561
});
562562
jar.setName(runNameContext("jar (unzip resources.apk)"));
563563
if (b.verbose) {
@@ -601,7 +601,7 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile {
601601
// - {directory with all resource files like: AndroidManifest.xml, res/values/strings.xml}
602602
const zip_file: LazyPath = blk: {
603603
const jar = b.addSystemCommand(&[_][]const u8{
604-
apk.tools.java_tools.jar,
604+
apk.sdk.java_tools.jar,
605605
});
606606
jar.setName(runNameContext("jar (zip compress apk)"));
607607

@@ -628,7 +628,7 @@ fn doInstallApk(apk: *Apk) std.mem.Allocator.Error!*Step.InstallFile {
628628
// Update zip with files that are not compressed (ie. resources.arsc)
629629
const update_zip: *Step = blk: {
630630
const jar = b.addSystemCommand(&[_][]const u8{
631-
apk.tools.java_tools.jar,
631+
apk.sdk.java_tools.jar,
632632
});
633633
jar.setName(runNameContext("jar (update zip with uncompressed files)"));
634634

@@ -723,7 +723,7 @@ fn getSystemIncludePath(apk: *Apk, target: ResolvedTarget) []const u8 {
723723
}
724724

725725
fn setLibCFile(apk: *Apk, compile: *Step.Compile) void {
726-
const tools = apk.tools;
726+
const tools = apk.sdk;
727727
const android_libc_path = tools.createOrGetLibCFile(compile, apk.api_level, apk.ndk.sysroot_path, apk.ndk.version);
728728
android_libc_path.addStepDependencies(&compile.step);
729729
compile.setLibCFile(android_libc_path);

src/androidbuild/tools.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ pub fn createKeyStore(sdk: *const Sdk, options: CreateKey) KeyStore {
320320
};
321321
}
322322

323-
pub fn createOrGetLibCFile(tools: *Sdk, compile: *Step.Compile, android_api_level: ApiLevel, ndk_sysroot_path: []const u8, ndk_version: []const u8) LazyPath {
324-
const b = tools.b;
323+
pub fn createOrGetLibCFile(sdk: *Sdk, compile: *Step.Compile, android_api_level: ApiLevel, ndk_sysroot_path: []const u8, ndk_version: []const u8) LazyPath {
324+
const b = sdk.b;
325325

326326
const target: ResolvedTarget = compile.root_module.resolved_target orelse @panic("no 'target' set on Android module");
327327
const system_target = getAndroidTriple(target) catch |err| @panic(@errorName(err));

0 commit comments

Comments
 (0)