Skip to content

Commit a538924

Browse files
fix bug where if NDK version isn't installed, you get a panic rather than a nice error message (#42)
fix bug raised on Github Issue #41 where if NDK version isn't installed, you get a panic rather than a nice error message Fixes #41
1 parent 37e4be6 commit a538924

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/androidbuild/Ndk.zig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,9 @@ pub fn init(b: *std.Build, android_sdk_path: []const u8, ndk_version: []const u8
112112
}
113113

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

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

152148
// Check if platforms/android-{api-level}/android.jar exists
153149
_ = blk: {
150+
// Get root jar path
151+
const root_jar = b.pathResolve(&[_][]const u8{
152+
ndk.android_sdk_path,
153+
"platforms",
154+
b.fmt("android-{d}", .{@intFromEnum(api_level)}),
155+
"android.jar",
156+
});
154157
std.fs.accessAbsolute(root_jar, .{}) catch |err| switch (err) {
155158
error.FileNotFound => {
156159
const message = b.fmt("Android API level {d} not installed. Unable to find '{s}'", .{

src/androidbuild/apk.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ pub fn create(sdk: *Sdk, options: Options) *Apk {
7171
error.NdkFailed => Ndk.empty, // fallthrough and print all errors below
7272
error.OutOfMemory => @panic("OOM"),
7373
};
74-
ndk.validateApiLevel(b, options.api_level, &errors);
74+
if (ndk.path.len != 0) {
75+
// Only do additional NDK validation if ndk is not set to Ndk.empty
76+
// ie. "ndk_version" isn't installed
77+
ndk.validateApiLevel(b, options.api_level, &errors);
78+
}
7579
if (errors.items.len > 0) {
7680
printErrorsAndExit("unable to find required Android installation", errors.items);
7781
}

0 commit comments

Comments
 (0)