Building an SDL2 program for Android.

Ok, so here is a little open source SDL program of mine that I would like to compile for Android..

Download:
SDL Connex

The game may be interest to some people here.
I am trying to make a script to build it for Android. From the top:

I am using Bookworm64 puppy linux, with devx, SDL2 and Android Studio installed. (I believe you can just install the command line Android NDK/SDK which is much smaller). Now I copy the whole sdl2 lib source folder to my project dir as a folder called SDL2, then I am building it with these commands (as a script):

  export ANDROID_HOME="/root/Android/Sdk"
  export ANDROID_NDK_HOME="/mnt/sda3/android-studio/plugins/android-ndk"
  SDL2/build-scripts/androidbuild.sh com.apm.sconnex sconnex.c sdlwio.c 

I get the reply:
./gradlew installDebug

Now I understand I need to connect my android phone in usb debugging mode, i am not clear how to do that outside studio, but maybe gradlew will sort it out?

I connect the phone and type
./gradlew installDebug

from the “SDL2/build/projectname” folder. when i do that, i get:

“Error: JAVA_HOME is not set and no ‘java’ command is in your path.”

I try:

export JAVA_HOME=“/mnt/sda3/android-studio/plugins/java”

but I still get an “invalid directory” error..

Any ideas?

EDIT:
so to enable usb debug mode you multi click on system/build, then enable usb debug from system/developer..

now i try:

export JAVA_HOME=“/mnt/sda3/android-studio/jbr/”
./gradlew installDebug

it runs! it downloads from gradle.org, but then:

Exception in thread “main” and a long list of errors..

Ok, so I have come back to this. I have made a new install for Android Studio under xubuntu 2404 lts.

I have installed SDL2 and it compiles my program ok. Source code here:
sconnex download

I followed the instructions in the sdl2 source docs for Android, put a folder SDL2 in the sconnex folder, from SDL2/build-scripts run
./androidbuild.sh com.apm.sconnex ../../sconnex.c ../../sdlwio.c
It generates build..
then i run ./gradlew installDebug

I get:

FAILURE: build failed with an exception.

Could not open settings general class cache for settings file
 [path]/settings.gradle
BUG! exception in phase semantic analysis in souce unit 
'_BuildScript_' unsupported class file major version 65.

So, does anyone understand what all this actually means?

I think gradle should be exterminated

Yeah, I don’t understand it. The build process should not be much more complex than:

cc sdlprog.c -o sdlprog-android-exec -lSDL2Android.lib -Os

yeah that’s more or less how you use Emscripten, no hassle. I wonder. perhaps it’s time to have some kind of wrapper that does the same magic Emscripten does, but for Android. in three months I will attempt something.

Well I have the command lines tools sort of working, according to instructions in this post:

https://forum.f-droid.org/t/sconnex-an-open-source-sdl-game-for-f-droid/31042/24


(From user Ammar64)
"I never use SDL2 androidbuild.sh script.
I setup cmake and build.

Here is what to do on a fresh linux installation to compile your game:

1- download cmdline-tools from here Download Android Studio & App Tools - Android Developers

image
2- extract it. then rename the directory named cmdline-tools to latest
3- make directories mkdir -p ~/Android/Sdk/cmdline-tools/ and move latest to it
4- run this command ~/Android/Sdk/cmdline-tools/latest/bin/sdkmanager --licenses to accept licenses. (you don’t need to accept all)
5- install java 17
6- add the environment variables ANDROID_HOME and JAVA_HOME in your ~/.bashrc

export JAVA_HOME=“/usr/lib/jvm/java-17-openjdk/” # Maybe different for your distro
export ANDROID_HOME=“$HOME/Android/Sdk/”
7- download and extract the game zip:

8- navigate to android-project in the zip file and run ./gradlew installDebug or ./gradlew assembleRelease

Now it should download the needed sdk and ndk and build.
You can read CMakeLists.txt in the zip file and android-project/app/build.gradle to learn how things work."


my reply:

Well the debug version now runs. At first it said “Install failed, no matching ABIS”. I had to change
app/build.gradle to include armeabi-v7a, changing:
abiFilters ‘armeabi-v7a’, ‘arm64-v8a’

(I dropped the x86 stuff for now) My debug phone is old ( but not very, android11). It also installed and ran on an old android 4 phone, which was useful, since I see some scaling issues. A few other bits need doing before release. It just comes up as “SDL GAME” when installed, I need to understand what to edit for names, icons etc.

When ready, should I upload the source to Github and send a Request for packaging? Do I just post my main SDL/C code, or all the other stuff?

I am still messing with things like apksigner, and learning about the tools.
I am not very clear what files in the game zip are std project files, and which are ones I need to customise.

The apk is about 1.5Mb. Is there much that can be done to make it smaller? (-Os?) Can I make the compiler not include unneeded SDL libs? (the linux version was about 10k excluding SDL libs).

I would like to learn some of the basic API calls in C needed to build a small apk, similar to simple win32/x11 programs that create a window, draw some rectangles, etc. (but not kotlin/java)
Any ideas?

Also is there any reason not to upload and post up a link to the debug apk somewhere? Or is it just bad form?

Thanks again..