SDL
SDL copied to clipboard
SDL3 Android Manual Build – App Won’t Start
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!
P.S. Sorry if this is not the best place for asking, feel free to close the issue.
These are the commands our test/CMakeLists.txt generates to create apks of the tests,
In general, it does:
- compile all java sources and put them in jars (our cmake script creates a jar for SDL3, and a jar for each test)
- run d8 on the jar(s)
- generate a debug key using keytool
aapt2 compileall Android resources (=files in theres/folder)aapt2 linkall files together (AndroidManifest.xmlis an argument here)- add all extra files to the apk zip file generated by the aapt2 link step
- run zipalign on the apk
- run apksigner on the apk
If SDL3 finds your android ndk and sdk, you can build apks of all SDL tests with the target names <testname>-apk.
e.g. ninja testsprite-apk or cmake --build . --target testcontroller-apk
I'm surprised you're using aapt. It's not mentioned on the cli page. Only aapt2.
The SDL tests don't need to generate Java bindings, so I don't know how to do this with the documented cli tools.
These are the commands our test/CMakeLists.txt generates to create apks of the tests,
In general, it does:
- compile all java sources and put them in jars (our cmake script creates a jar for SDL3, and a jar for each test)
- run d8 on the jar(s)
- generate a debug key using keytool
aapt2 compileall Android resources (=files in theres/folder)aapt2 linkall files together (AndroidManifest.xmlis an argument here)- add all extra files to the apk zip file generated by the aapt2 link step
- run zipalign on the apk
- run apksigner on the apk
If SDL3 finds your android ndk and sdk, you can build apks of all SDL tests with the target names
<testname>-apk. e.g.ninja testsprite-apkorcmake --build . --target testcontroller-apkI'm surprised you're using
aapt. It's not mentioned on the cli page. Onlyaapt2. The SDL tests don't need to generate Java bindings, so I don't know how to do this with the documented cli tools.
Hey, I was using outdated guide (https://hereket.com/posts/android_from_command_line/) which worked for simple case. Upgrading it to sdl example was not successful.
Im gonna check tests to see if there is anything i could use
Closing since this does not appear to be an SDL issue.