This library allows you to setup and build an APK for your Android devices. This project was mostly based off the work of ikskuh and wouldn't exist without the work they did on the ZigAndroidTemplate project.
# Target one Android architecture
zig build -Dtarget=x86_64-linux-android
# Target all Android architectures
zig build -Dandroid=true
// This is an overly simplified example to give you the gist
// of how this library works, see: examples/minimal/build.zig
const android = @import("zig-android-sdk");
pub fn build(b: *std.Build) !void {
const android_tools = android.Tools.create(b, ...);
const apk = android.APK.create(b, android_tools);
apk.setAndroidManifest(b.path("android/AndroidManifest.xml"));
apk.addResourceDirectory(b.path("android/res"));
apk.addJavaSourceFile(.{ .file = b.path("android/src/NativeInvocationHandler.java") });
for (android.standardTargets(b, b.standardTargetOptions(.{}))) |target| {
apk.addArtifact(b.addSharedLibrary(.{
.name = exe_name,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}))
}
}
- Zig
- Android Tools
- Option A: Android Studio
- Option B: Android Command Line Tools
- Java Development Kit
Add the following to your build.zig.zon file and run zig build
.
.{
.dependencies = .{
.@"zig-android-sdk" = .{
.path = "https://github.com/silbinarywolf/zig-android-sdk/archive/REPLACE_WITH_WANTED_COMMIT.tar.gz",
// .hash = REPLACE_WITH_HASH_FROM_BUILD_ERROR
},
},
}
- minimal: This is based off ZigAndroidTemplate's minimal example.
- SDL2: This is based off Andrew Kelly's SDL Zig Demo but modified to run on Android, Windows, Mac and Linux.
- ikskuh This would not exist without their ZigAndroidTemplate repository to use as a baseline for figuring this all out and also being able to use their logic for the custom panic / logging functions.
- ikskuh gave a huge thanks to @cnlohr for rawdrawandroid