Skip to content
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

Enhance Quick-Start Documentation and NDK compatiblity ? #12

Open
gajanak opened this issue Jul 27, 2022 · 0 comments
Open

Enhance Quick-Start Documentation and NDK compatiblity ? #12

gajanak opened this issue Jul 27, 2022 · 0 comments

Comments

@gajanak
Copy link

gajanak commented Jul 27, 2022

Hi,
at first thanks for this usefull template.

Perhaps this hels someone using this as base.

Documentation Quick-Start:
Installting android sdk,ndk,platforms using dpkg/apt sample:
apt install google-android-ndk-r25-installer install google-android-platform-30-installer google-android-build-tools-33.0.0-installer

for jarsigner:
apt install openjdk-19-jdk-headless

Using Build Tools > 22

The sysroot moved to /toolchains/llvm/prebuilt//sysroot starting with NDK r19. r22 removed the deprecated sysroot and platforms directories from the top-level of the NDK.

So this dirty hack to Sdk.zig are working (not perfect but perhaps a Hint for anyone with more experience):

diff --git a/Sdk.zig b/Sdk.zig
index 58e3b50..a6eb83a 100644
--- a/Sdk.zig
+++ b/Sdk.zig
@@ -81,9 +81,9 @@ pub fn init(b: *Builder, user_config: ?UserConfig, versions: ToolchainVersions)
 }

 pub const ToolchainVersions = struct {
-    android_sdk_version: u16 = 28,
-    build_tools_version: []const u8 = "28.0.3",
-    ndk_version: []const u8 = "21.1.6352462",
+    android_sdk_version: u16 = 30,
+    build_tools_version: []const u8 = "33.0.0",
+    ndk_version: []const u8 = "25.0.8775105",

     pub fn androidSdkString(self: ToolchainVersions, buf: *[5]u8) []u8 {
         return std.fmt.bufPrint(buf, "{d}", .{self.android_sdk_version}) catch unreachable;
@@ -561,7 +561,7 @@ pub fn compileAppLibrary(

     exe.defineCMacro("ANDROID", null);

-    const include_dir = std.fs.path.resolve(sdk.b.allocator, &[_][]const u8{ ndk_root, "sysroot/usr/include" }) catch unreachable;
+    const include_dir = std.fs.path.resolve(sdk.b.allocator, &[_][]const u8{ ndk_root, "toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" }) catch unreachable;
     exe.addIncludeDir(include_dir);

     exe.linkLibC();
@@ -572,66 +572,49 @@ pub fn compileAppLibrary(
     exe.setBuildMode(mode);

     const TargetConfig = struct {
-        lib_dir: []const u8,
         include_dir: []const u8,
-        libgcc_dir: []const u8,
         out_dir: []const u8,
         target: std.zig.CrossTarget,
     };

     const config: TargetConfig = switch (target) {
         .aarch64 => TargetConfig{
-            .lib_dir = "arch-arm64/usr/lib",
-            .libgcc_dir = "aarch64-linux-android-4.9",
             .include_dir = "aarch64-linux-android",
             .out_dir = "arm64-v8a",
             .target = zig_targets.aarch64,
         },
         .arm => TargetConfig{
-            .lib_dir = "arch-arm/usr/lib",
-            .libgcc_dir = "arm-linux-androideabi-4.9",
             .include_dir = "arm-linux-androideabi",
             .out_dir = "armeabi",
             .target = zig_targets.arm,
         },
         .x86 => TargetConfig{
-            .lib_dir = "arch-x86/usr/lib",
-            .libgcc_dir = "x86-4.9",
             .include_dir = "i686-linux-android",
             .out_dir = "x86",
             .target = zig_targets.x86,
         },
         .x86_64 => TargetConfig{
-            .lib_dir = "arch-x86_64/usr/lib64",
-            .libgcc_dir = "x86_64-4.9",
             .include_dir = "x86_64-linux-android",
             .out_dir = "x86_64",
             .target = zig_targets.x86_64,
         },
     };

-    const lib_dir_root = sdk.b.fmt("{s}/platforms/android-{d}", .{
+    const lib_dir = sdk.b.fmt("{s}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/{s}-linux-android/{}/",.{
         ndk_root,
+        @tagName(target),
         sdk.versions.android_sdk_version,
     });

-    const lib_dir = std.fs.path.resolve(sdk.b.allocator, &[_][]const u8{ lib_dir_root, config.lib_dir }) catch unreachable;
-
-    const prebuilt_dir = switch (builtin.os.tag) {
-        .windows => "windows",
-        .linux => "linux",
-        .macos => "darwin",
-        else => unreachable,
-    };
-
-    const libgcc_path = sdk.b.fmt(
-        "{s}/toolchains/{s}/prebuilt/{s}-x86_64/lib/gcc/{s}/4.9.x/libgcc.a",
-        .{ ndk_root, config.libgcc_dir, prebuilt_dir, config.include_dir },
-    );
+    //const prebuilt_dir = switch (builtin.os.tag) {
+    //    .windows => "windows",
+    //    .linux => "linux",
+    //    .macos => "darwin",
+    //    else => unreachable,
+    //};

     exe.setTarget(config.target);
     exe.addLibPath(lib_dir);
-    exe.addObjectFile(libgcc_path);
     exe.addIncludeDir(std.fs.path.resolve(sdk.b.allocator, &[_][]const u8{ include_dir, config.include_dir }) catch unreachable);

     exe.setLibCFile(sdk.createLibCFile(config.out_dir, include_dir, include_dir, lib_dir) catch unreachable);
diff --git a/build/auto-detect.zig b/build/auto-detect.zig
index 98bafce..2bfd5bc 100644
--- a/build/auto-detect.zig
+++ b/build/auto-detect.zig
@@ -458,6 +458,10 @@ fn findProblemWithAndroidNdk(b: *Builder, versions: Sdk.ToolchainVersions, path:

     const ndk_include_path = std.fs.path.join(b.allocator, &[_][]const u8{
         path,
+"toolchains",
+"llvm",
+"prebuilt",
+"linux-x86_64", //<host-tag>
         "sysroot",
         "usr",
         "include",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant