SCONNEX, an open source SDL game for F-Droid

Ok, so heres an open source SDL program I have written that I would like to compile for Android and submit to f-droid…

SDL-Connex

(SDL version)

A quick summary: SCONNEX is a version of the famous 4-in-a-line game, written to work on almost any computer. It can compile to work as an SDL app (screen shot above) or as a C99 terminal program. The compiled executable is only 10-20k, yet it can search 20+ moves ahead midgame in a few seconds on modern PCs. The board size can be changed from 4x4 upto 12x12, there is an edit board function to setup positions, and a two player mode to use the program for human games. The code uses the classic recursive AlphaBeta search algorithm, and is a useful example of its use. It is still a “work in progress”, yet it is good enough to be a challenging game. For more program details see file “sconnex.txt”

Ok, so what I would really like is a simple way to build this program for Android. Frankly I find Android Studio a pain - I really just want a simple C compiler to compile with the command line. Has anyone made a simple way to do this for an SDL C program?

The app as it stands will scale itself for any screen size.

Anyway, thoughts welcome…

1 Like

You don’t have to deal with android studio to build SDL2 game.

I tried to compile it but I don’t know to which library do these functions belong

/usr/bin/ld: sconnex.c:(.text+0x1ec7): undefined reference to `SDLTXT_SetScale'
/usr/bin/ld: sconnex.c:(.text+0x1ed6): undefined reference to `SDLTXT_SetCursorPos'
/usr/bin/ld: sconnex.c:(.text+0x1eea): undefined reference to `SDLTXT_SetColor'
/usr/bin/ld: sconnex.c:(.text+0x1ef9): undefined reference to `SDLTXT_PrintStr'
/usr/bin/ld: sconnex.c:(.text+0x1f0d): undefined reference to `SDLTXT_SetColor'
/usr/bin/ld: sconnex.c:(.text+0x1f1c): undefined reference to `SDLTXT_PrintStr'
/usr/bin/ld: sconnex.c:(.text+0x1f30): undefined reference to `SDLTXT_SetColor'
/usr/bin/ld: sconnex.c:(.text+0x1f3f): undefined reference to `SDLTXT_PrintStr'
/usr/bin/ld: sconnex.c:(.text+0x1f53): undefined reference to `SDLTXT_SetColor'
/usr/bin/ld: sconnex.c:(.text+0x1f62): undefined reference to `SDLTXT_PrintStr'
/usr/bin/ld: sconnex.c:(.text+0x1f76): undefined reference to `SDLTXT_SetColor'
/usr/bin/ld: sconnex.c:(.text+0x1f85): undefined reference to `SDLTXT_PrintStr'

I managed to make it work.
Just uncompress the zip file

cd android
./gradlew installDebug

sconnex155-android.zip (1.3 MB)

but you have to download the source code SDL-2.32.2
and rename the folder to SDL2 then put it in the root of the zip file

don’t forget to edit android/app/build.gradle to set an applicationId for your game.

Thanks ammar
so thats now a setup to submit to fdroid? or the files of the converted app to run on my local copy of studio? I have been trying to read fdroids help on submitting apps, it seems i have to set up a web folder with the app project (on github?), install fdroids app (can it run in linux?)…
You can see i dont know how fdroid works!
I did find some docs on building sdl apps for Android, i will have to work through those…

If someone connected to fdroid wanted to build and add sconnex to fdroid, while i am trying to learn about it all, feel free!

I have gone back to just try and learn about using Studio.
I have installed Android Studio, and managed to build very simple code, but frankly I struggle with it. It gets upset very easily, and it keeps demanding connection back to google - why cant we just download the compiler in one go?

I have tried different approaches, including the way given in “docs/README-android.md” in the SDL2 source download, see: GitHub - libsdl-org/SDL: Simple Directmedia Layer

I copy sdl2 folder to project dir, from there type:

ANDROID_HOME=“/root/Android/Sdk”

SDL2/build-scripts/androidbuild.sh/ com.me.sconnex sconnex.c sdlwio.c

It keeps asking me to set ANDROID_HOME to sdk path.

Given that SDL is a clear well know popular cross-platform standard, there should be a simple, well documented step-by-step way to do this.

Ideas still welcome!

append

export ANDROID_HOME=“/root/Android/Sdk”

to your .bashrc file
assuming you truely have the Sdk there
The Sdk is usually installed at ~/Android/Sdk

Thiank you!
Ok now, first I copy the SDL2 library source to a folder SDL2 in my app dir, then I am building it with these commands (in a bash 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 what? Do I type that in studio or NDK somewhere?

I would like to build the “debug” apk and copy to my phone. I am still unclear on the process for submitting that to fdroid. I haven’t installed the fdroid app yet…

Really what I am aiming to do is develop in C/SDL using an editor/compiler I like and am familiar with, then port over to Android (or iOS) for final testing.

You can’t just copy the debug apk to your phone it won’t install as it’s not signed.
./gradlew installDebug builds and install it on your phone. You need to connect your phone with you PC with USB and enable USB debugging in developer settings.
If you need an apk that you want to copy and install you have to sign it first.
you can find the apk if you build with gradlew at app/outputs/apk/release as I remember.

You type ./gradlew installDebug in your terminal.

cd /path/to/your/project
./gradlew installDebug

Ok, thanks. After a few retries, some progress. 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 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 to connect 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”

first, but I still get an “invalid directory” error…

EDIT:
so this enables usb debug mode:

link…

so 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…

Could you do

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk/

make sure to pick the directory where java installed and see which java version you have.

Thanks again for helping Ammar.

Well when I started all this I had assumed Android Studio supplied the SDK, NDK, the version of JAVA it needed to work, and furthermore would set the right paths to all these things for command line builds
too, and supply readable documents for use, like other IDE compiler tools.
(gnu gcc, MS Visual Studio, etc).

Seems I was wrong.

I went back and setup java:
apt install default-jdk
which runs fine, compiling simple java console programs.
So I got a bit further, but still no luck.
This is my build-file, with SDL2 a folder within the sconnex155s folder:

-----------------------------------------------------------  
#!/bin/sh
# Build script for SDL2->Android
# syntax: ./makand.sh appname file1.c [file2.c..]
#ie: ./makand.sh com.author.hello helloworld.c
#ie: ./makand.sh com.apm.sconnex sconnex.c sdlwio.c
PATH="/mnt/sda3/android-studio/plugins/android-ndk:$PATH"
PATH="/root/Android/Sdk/tools:$PATH"
PATH="/root/Android/Sdk/platform-tools:$PATH"
export ANDROID_HOME="/root/Android/Sdk"
export ANDROID_NDK_HOME="/mnt/sda3/android-studio/plugins/android-ndk"
#export JAVA_HOME="/mnt/sda3/android-studio/jbr/"
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"

#SDL2/build-scripts/androidbuild.sh com.apm.sconnex sconnex.c sdlwio.c 
SDL2/build-scripts/androidbuild.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
cd SDL2/build/$1
./gradlew installDebug
-----------------------------------------------------------

When I run

  ./makand.sh com.apm.sconnex sconnex.c sdlwio.c

I get:

-----------------------------------------------------------
./makand.sh com.apm.sconnex sconnex.c sdlwio.c
To build and install to a device for testing, run the following:
cd /mnt/sda3/w/sconnex155s/SDL2/build/com.apm.sconnex
./gradlew installDebug

> Configure project :app
This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
Warning: Errors during XML parse:
Warning: Additionally, the fallback loader failed to parse the XML.
Checking the license for package NDK (Side by side) 25.1.8937393 in /root/Android/Sdk/licenses
License for package NDK (Side by side) 25.1.8937393 accepted.
Preparing "Install NDK (Side by side) 25.1.8937393 v.25.1.8937393".
<======-------> 50% CONFIGURING [4m 37s]
> :app
----------------------------------------------------------------------------

And it just sits there. (phone in usb debug mode connected). The Android tools are not providing useful/adequate information on what is going wrong. Sometimes I get:

A problem occurred configuring project ':app'.
> [CXX1101] NDK at /root/Android/Sdk/ndk/25.1.8937393 did not have a source.properties file

(Deleting the folder clears the error, but still no joy)

I have tried also adding a build.gradle file with this:

android {
  defaultConfig {
    applicationId "com.apm.sconnex"
    minSdkVersion 15
    minSdkVersion 30
    versionCode 1
    versionName "1.0"
  }
  ...
}

but it does not work. It nearly works, but…

Figuring I might have somehow messed something up, I have started to make a fresh minimal install of linux (Bookworm pup64) with just the command line tools needed, no studio, if that is possible.

But it is difficult to find good documents on the command line tools (particularly clear, simple well explained examples for building from the command line, what the components do, etc).