This repository contains a example on how to create a minimal Android app in Zig.
This project contains a really small app skeleton in example/main.zig
which initializes OpenGL and renders a color cycle. Touchscreen events will be displayed as small circles beneath the fingers that will fade as soon as no event for the same finger will happen again.
The code contains some commented examples on how to interface with the JNI to use advanced features of the ANativeActivity
.
It has no dependencies to C code except for the android libraries, so it can be considered a pure Zig app.
We're running a CI that will verify the build for Windows, macOS and Linux:
There is a FOSDEM Talk you can watch here:
- Configuration management example
- Save/load app state example
You need the Android SDK installed together with the Android NDK.
You also need adb and a Java SDK installed (required for jarsigner
).
Now you need to generate yourself a keystore to sign your apps. For debugging purposes, the build script contains a helper. Just invoke zig build keystore
to generate yourself a debug keystore that can be used with later build invocations.
Note that the build file might ask you to configure some paths. Do as requested and just run the build again, it should work then.
If all of the above is done, you should be able to build the app by running zig build
.
There are convenience options with zig build push
(installs the app on a connected phone) and zig build run
(which installs, then runs the app).
Install the sdkmanager
and invoke the following command line:
# Android Platforms for your target Android version
# Min version: Android 5
sdkmanager --install "platforms;android-21"
# you can install other versions as well
# remember to set it like `zig build -Dandroid=android99`
sdkmanager --install "build-tools;33.0.1"
sdkmanager --install "ndk;25.1.8937393"
zig build keystore install run
This should build an APK and install it on your connected phone if possible.
Check out the build.zig
to see how to build a new android app, and example/main.zig
to see how to create a basic application. All of this is still very rough, though.
Huge thanks to @cnlohr to create rawdrawandroid and making this project possible!