This is a template for building a raylib-zig game for android, please note that the solution is extremely wacky and anything can fail.
- Android NDK
- Gradle
- A Raylib .a file compiled for Android (Depending on target archtitecture)
Note
armv7 is not properly tested since i don't have an armv7 android 10+ device (see below)
- Android 10 or higher
- It may probably run on older devices, but LLVM builds and expects
native thread-local storage, so runtime crash withunknown reloc type 17 @ 0x9c436c64 (531), and even assigning __gshared to everything, not even the simplest example runs, failing withdlopen failed: cannot locate symbol "pthread_attr_setinheritsched"(Android 9+).
- It may probably run on older devices, but LLVM builds and expects
- Clone and build raylib
git clone https://github.com/raysan5/raylib
cd raylib/src
make PLATFORM=PLATFORM_ANDROID \
ANDROID_NDK=/path/to/your/android-ndk \
ANDROID_ARCH=arm64 \
ANDROID_API_VERSION=29
Replace
aarch64tox86_64orarmif needed
- Place your raylib in
raylib-androidaccording to the desired archtitecture, for example:
-> tree raylib-android/
raylib-android/
├── arm64-v8a
│ └── libraylib.a
└── x86_64
└── libraylib.a
- Add submodule
git submodule add https://github.com/zariep-software/raylib-zig-android-template.git vendor/raylib-zig-android
- Define environment variables
export ANDROID_NDK_HOME=/opt/android-ndk
export RAYLIB_LIB_DIR=/home/user/raylib-android/
export ANDROID_OUTPUT_DIR=/path/to/your/apk/setup/
Replace those paths with the actual paths, or copy
asetup.exampletoasetup.shand edit it.build-android.zigloads simpleKEY=VALUElines fromasetup.shautomatically if the file exists, and expands$VAR,${VAR}, and a leading~(e.g.$USER,$HOME) the same way a shell would.
- Copy
examples/build.zigor adapt it to your project
zig build android -Dabi=arm64-v8aTo build for multiple architectures in one go just call it once per ABI, Each run writes its output to
android/app/src/main/jniLibs/<ABI>/libmain.so, so subsequent runs for different ABIs don't overwrite each other. The resultingjniLibs/tree can then be picked up as is by a single Gradle build producing a multi-ABI APK/AAB.
gradle wrapper # You may need to get gradlew jar first time
./gradlew assembleDebug
More information about setting up a game for android in raylib-zig (e.g. Setting up / troubleshoot things like rotation, Touch screen or screen size) available on the wiki