Skip to content

Commit 94c6837

Browse files
committed
more
1 parent f80aab4 commit 94c6837

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ zig build -Dandroid=true
1818
const android = @import("android");
1919
2020
pub fn build(b: *std.Build) !void {
21-
const android_tools = android.Tools.create(b, .{});
22-
const apk = android.Apk.create(b, android_tools, .{
21+
const android_sdk = android.Sdk.create(b, .{});
22+
const apk = android_sdk.createApk(.{
2323
.api_level = .android15,
2424
.build_tools_version = "35.0.1",
2525
.ndk_version = "29.0.13113456",

src/androidbuild/tools.zig

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ cmdline_tools: struct {
3434
/// lint [flags] <project directory>
3535
/// See documentation: https://developer.android.com/studio/write/lint#commandline
3636
lint: []const u8,
37+
sdkmanager: []const u8,
3738
},
3839
/// Binaries provided by the JDK that usually exist in:
3940
/// - Non-Windows: $JAVA_HOME/bin
@@ -143,17 +144,18 @@ pub fn create(b: *std.Build, options: Options) *Sdk {
143144
const exe_suffix = if (host_os_tag == .windows) ".exe" else "";
144145
const bat_suffix = if (host_os_tag == .windows) ".bat" else "";
145146

146-
const tools: *Sdk = b.allocator.create(Sdk) catch @panic("OOM");
147-
tools.* = .{
147+
const sdk: *Sdk = b.allocator.create(Sdk) catch @panic("OOM");
148+
sdk.* = .{
148149
.b = b,
149150
.android_sdk_path = android_sdk_path,
150151
.jdk_path = jdk_path,
151152
.cmdline_tools = .{
152153
.lint = b.pathResolve(&[_][]const u8{
153154
cmdline_tools_path, b.fmt("lint{s}", .{bat_suffix}),
154155
}),
155-
// NOTE(jae): 2024-09-28
156-
// Consider adding sdkmanager.bat so you can do something like "zig build sdkmanager -- {args}"
156+
.sdkmanager = b.pathResolve(&[_][]const u8{
157+
cmdline_tools_path, b.fmt("sdkmanager{s}", .{bat_suffix}),
158+
}),
157159
},
158160
.java_tools = .{
159161
.jar = b.pathResolve(&[_][]const u8{
@@ -167,11 +169,32 @@ pub fn create(b: *std.Build, options: Options) *Sdk {
167169
}),
168170
},
169171
};
170-
return tools;
172+
return sdk;
173+
}
174+
175+
pub fn createApk(sdk: *Sdk, options: Apk.Options) *Apk {
176+
return Apk.create(sdk, options);
171177
}
172178

173-
pub fn createApk(tools: *Sdk, options: Apk.Options) *Apk {
174-
return Apk.create(tools, options);
179+
// TODO: Consider adding step to run: sdkmanager --install "ndk;21.3.6528147"
180+
// pub fn installNdkVersion(ndk_version: []const u8) *Step {
181+
// }
182+
183+
/// EXPERIMENTAL: Allows invoking the Android SDK manager
184+
/// ie. zig build -Dandroid sdkmanager -- --help
185+
pub fn addSdkManagerStep(sdk: *Sdk) void {
186+
const b = sdk.b;
187+
const sdkmanager_step = b.step("sdkmanager", "Run the Android SDK Manager");
188+
const args = b.args orelse &.{};
189+
const sdkmanager = b.addSystemCommand(&.{sdk.cmdline_tools.sdkmanager});
190+
sdkmanager.setEnvironmentVariable("SKIP_JDK_VERSION_CHECK", "1");
191+
if (b.verbose) {
192+
sdkmanager.addArg("--verbose");
193+
}
194+
sdkmanager_step.dependOn(&sdkmanager.step);
195+
for (args) |arg| {
196+
sdkmanager.addArg(arg);
197+
}
175198
}
176199

177200
pub const CreateKey = struct {
@@ -206,11 +229,11 @@ pub const CreateKey = struct {
206229
};
207230
};
208231

209-
pub fn createKeyStore(tools: *const Sdk, options: CreateKey) KeyStore {
210-
const b = tools.b;
232+
pub fn createKeyStore(sdk: *const Sdk, options: CreateKey) KeyStore {
233+
const b = sdk.b;
211234
const keytool = b.addSystemCommand(&.{
212235
// https://docs.oracle.com/en/java/javase/17/docs/specs/man/keytool.html
213-
tools.java_tools.keytool,
236+
sdk.java_tools.keytool,
214237
"-genkey",
215238
"-v",
216239
});
@@ -303,10 +326,6 @@ pub fn createOrGetLibCFile(tools: *Sdk, compile: *Step.Compile, android_api_leve
303326
return android_libc_path;
304327
}
305328

306-
pub fn getSystemIncludePath(_: *const Sdk, _: ResolvedTarget) []const u8 {
307-
@compileError("getSystemIncludePath has moved from Tools to Apk");
308-
}
309-
310329
/// Search JDK_HOME, and then JAVA_HOME
311330
fn getJDKPath(allocator: std.mem.Allocator) error{OutOfMemory}![]const u8 {
312331
const jdkHome = std.process.getEnvVarOwned(allocator, "JDK_HOME") catch |err| switch (err) {

0 commit comments

Comments
 (0)