Skip to content

fix bug where if NDK version isn't installed, you get a panic rather than a nice error message #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
17 changes: 10 additions & 7 deletions src/androidbuild/Ndk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,9 @@ pub fn init(b: *std.Build, android_sdk_path: []const u8, ndk_version: []const u8
}

pub fn validateApiLevel(ndk: *const Ndk, b: *std.Build, api_level: ApiLevel, errors: *std.ArrayList([]const u8)) void {
// Get root jar path
const root_jar = b.pathResolve(&[_][]const u8{
ndk.android_sdk_path,
"platforms",
b.fmt("android-{d}", .{@intFromEnum(api_level)}),
"android.jar",
});
if (ndk.android_sdk_path.len == 0 or ndk.sysroot_path.len == 0) {
@panic("Should not call validateApiLevel if NDK path is not set");
}

// Check if NDK sysroot/usr/lib/{target}/{api_level} path is accessible
_ = blk: {
Expand Down Expand Up @@ -151,6 +147,13 @@ pub fn validateApiLevel(ndk: *const Ndk, b: *std.Build, api_level: ApiLevel, err

// Check if platforms/android-{api-level}/android.jar exists
_ = blk: {
// Get root jar path
const root_jar = b.pathResolve(&[_][]const u8{
ndk.android_sdk_path,
"platforms",
b.fmt("android-{d}", .{@intFromEnum(api_level)}),
"android.jar",
});
std.fs.accessAbsolute(root_jar, .{}) catch |err| switch (err) {
error.FileNotFound => {
const message = b.fmt("Android API level {d} not installed. Unable to find '{s}'", .{
Expand Down
6 changes: 5 additions & 1 deletion src/androidbuild/apk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ pub fn create(sdk: *Sdk, options: Options) *Apk {
error.NdkFailed => Ndk.empty, // fallthrough and print all errors below
error.OutOfMemory => @panic("OOM"),
};
ndk.validateApiLevel(b, options.api_level, &errors);
if (ndk.path.len != 0) {
// Only do additional NDK validation if ndk is not set to Ndk.empty
// ie. "ndk_version" isn't installed
ndk.validateApiLevel(b, options.api_level, &errors);
}
if (errors.items.len > 0) {
printErrorsAndExit("unable to find required Android installation", errors.items);
}
Expand Down
Loading