Hi, everyone.
I’m automating the Android build process for an SDL3-based project without using Gradle. While SDL provides an Android project template, it doesn’t fully cover my case, so I’m customizing it to support prebuilt native libraries and a manual build chain.
I’m using CMake with the Android NDK and toolchain to build my native code, and that part works fine. Here’s a snippet:
# Shared libs are on
if(ANDROID)
add_library(main SHARED "src/potok/main.c")
target_link_libraries(main log SDL3::SDL3)
endif()
// main.c
// main.c
#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
...
// SDL_AppInit, SDL_AppIterate, SDL_AppEvent, SDL_AppQuit implemented
// Using SDL_Renderer to clear screen with random color when screen is pressed
// Works on desktop
This builds libmain.so
and libSDL3.so
.
I’m using the SDL-provided android-template but with my own native libs. Key layout:
📦android-tmp
┣ 📂build/apk/lib/arm64-v8a/
┃ ┣ 📜libmain.so # Not sure how main interacts with SDL3 as they are dynamically linked
┃ ┗ 📜libSDL3.so
┣ 📂java/org/libsdl/app/
┃ ┣ 📜SDLActivity.java
┃ ┗ ...
┣ 📜AndroidManifest.xml (just added missing package name: org.libsdl.app)
# Helper stuff
┣ 📜android.jar
┣ 📜keystore.jks
No changes to Java code; I only added the package
attribute in the manifest.
Lastly, here are my commands that i used:
# 1. AAPT: Generate Java bindings
aapt package -f -m -J build/gen -S res -M AndroidManifest.xml -I android.jar
# 2. Compile Java (Java 17 here)
javac --release 17 -classpath android.jar -d build/obj build/gen/org/libsdl/app/*.java java/org/libsdl/app/*.java
# 3. D8 -> classes.jar
d8 build/obj/org/libsdl/app/*.class --output build/apk/classes.jar --no-desugaring --min-api 34
# 4. Final dex
d8 android.jar classes.jar --output build/apk/
# 5. AAPT: Package APK
aapt package -f -M AndroidManifest.xml -S res -I android.jar -F build/app.unsigned.apk build/apk/
# 6. Align & sign
zipalign -f -p 4 build/app.unsigned.apk build/app.aligned.apk
apksigner sign --ks keystore.jks --ks-key-alias androidkey \
--ks-pass pass:android --key-pass pass:android \
--out build/app.apk build/app.aligned.apk
# 7. Install
adb install -r build/app.apk
Issue
The app installs, but won’t launch at all, and logcat shows no concrete errors. I suspect something might be wrong with the context which might be set differently by SDL3 scripts.
If you could help me find out in running this up, I would be grateful.
Thanks!