Skip to content

This library allows you to setup and build an APK for your Android devices

License

Notifications You must be signed in to change notification settings

silbinarywolf/zig-android-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig Android SDK

Continuous integration

⚠️ WARNING: This is a work-in-progress and will be updated as I improve it for my personal SDL2 / OpenXR project.

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,
        }))
    }
}

Requirements

Installation

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
        },
    },
}

Examples

  • 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.

Credits

  • 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.

About

This library allows you to setup and build an APK for your Android devices

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages