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
3 changes: 3 additions & 0 deletions src/androidbuild/androidbuild.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ const AndroidTargetQuery = struct {
.abi = if (android_target.cpu_arch != .arm) .android else .androideabi,
.cpu_arch = android_target.cpu_arch,
.cpu_features_add = android_target.cpu_features_add,
// TODO(jae): 2025-05-11
// Setup Android API Level for Zig 0.14.0+
// .android_api_level = null,
};
}
};
Expand Down
75 changes: 75 additions & 0 deletions src/androidbuild/tools.zig
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,81 @@ fn getAndroidSDKPath(allocator: std.mem.Allocator) error{OutOfMemory}![]const u8
defer allocator.free(user);
return try std.fmt.allocPrint(allocator, "/Users/{s}/Library/Android/sdk", .{user});
},
// NOTE(jae: 2025-05-11
// Auto-discovery of Android SDK for Linux
// - /home/AccountName/Android/Sdk
// - /usr/lib/android-sdk
// - /Library/Android/sdk
// - /Users/[USER]/Library/Android/sdk
// Source: https://stackoverflow.com/a/34627928
.linux => {
{
const android_sdk_path = "/usr/lib/android-sdk";
const has_path: bool = pathblk: {
std.fs.accessAbsolute(android_sdk_path, .{}) catch |err| switch (err) {
error.FileNotFound => break :pathblk false, // fallthrough and try next
else => std.debug.panic("{s} has error: {}", .{ android_sdk_path, err }),
};
break :pathblk true;
};
if (has_path) {
return android_sdk_path;
}
}

{
const android_sdk_path = "/Library/Android/sdk";
const has_path: bool = pathblk: {
std.fs.accessAbsolute(android_sdk_path, .{}) catch |err| switch (err) {
error.FileNotFound => break :pathblk false, // fallthrough and try next
else => std.debug.panic("{s} has error: {}", .{ android_sdk_path, err }),
};
break :pathblk true;
};
if (has_path) {
return android_sdk_path;
}
}

// Check user paths
// - /home/AccountName/Android/Sdk
// - /Users/[USER]/Library/Android/sdk
const user = std.process.getEnvVarOwned(allocator, "USER") catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.EnvironmentVariableNotFound => &[0]u8{},
error.InvalidWtf8 => @panic("USER environment variable is invalid UTF-8"),
};
if (user.len > 0) {
{
const android_sdk_path = try std.fmt.allocPrint(allocator, "/Users/{s}/Library/Android/sdk", .{user});
const has_path: bool = pathblk: {
std.fs.accessAbsolute(android_sdk_path, .{}) catch |err| switch (err) {
error.FileNotFound => break :pathblk false, // fallthrough and try next
else => std.debug.panic("{s} has error: {}", .{ android_sdk_path, err }),
};
break :pathblk true;
};
if (has_path) {
return android_sdk_path;
}
}
{
// NOTE(jae): 2025-05-11
// No idea if /AccountName/ maps to $USER but going to assume it does for now.
const android_sdk_path = try std.fmt.allocPrint(allocator, "/home/{s}/Android/Sdk", .{user});
const has_path: bool = pathblk: {
std.fs.accessAbsolute(android_sdk_path, .{}) catch |err| switch (err) {
error.FileNotFound => break :pathblk false, // fallthrough and try next
else => std.debug.panic("{s} has error: {}", .{ android_sdk_path, err }),
};
break :pathblk true;
};
if (has_path) {
return android_sdk_path;
}
}
}
},
else => {},
}
return &[0]u8{};
Expand Down