SCONNEX, an open source SDL game for F-Droid

Ok thanks again, I downloaded and will try that.
The game compiles with SDL2 32/64 bit linux ok, but I note that the SDL build scipt copies the files before compiling, the header file sdlwio.h needs to be present, as well as sdlwio.c and sconnex.c.
You could just replace #include “sdlwio.h” in both c files with the content of sdlwio.h, to avoid path problems.

What version of the ndk and sdk are you using?
But I do wonder now whether to try another setup with a new xubuntu, not bother with studio and download exact versions of the jdk, sdk, ndk, gradle, and cmdline tools in an exact setup. ie:

wget https://dl.google.com/android/repository/android-ndk-r29-beta1-linux.zip

was the automatic download that studio did. But maybe the SDL2 androidbuild.sh script isnt compatible with that beta? It was trying to download ndk ver 25, but failing to do so.

But maybe something like gradle will just ignore that insist some other download?

I literally just downloaded cmdline tools from google and copied it to the right path and added the ANDROID_HOME environment variable. accepted licenses using sdkmanager. then ./gradlew assembleRelease and it automatically downloads the SDK and the NDK.

I added cmake code and modified the main functions to be compatible with SDL_main.

All changes are in the zip file.
I made the zip file after a successful build.
So if you extract the zip file you will find apk in android-project/app/build/outputs/apk/release/app-release-unsigned.apk

but it’s unsigned so it can’t be installed until you sign it.
or use AppManager to sign apk.

(I linked to the version 4.0.2 of AppManager because the latest one has a fatal bug that make it crash when using search).

1 Like

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

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 the zip Download game.zip | LimeWire I posted earlier and extract.
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.

Thanks again Ammar. So I have run through all this, re-installing xubuntu, then everything in your last post, up until

./gradlew assembleRelease

First try it downloaded gradle ok, then just hung at 50%, eventually i stopped it.
(I seem to remember this happening before)

I tried again, it fails with:

[CX1101] NDK at [ndk path] did not have a source properties file.

The ndk folder is empty, so it did not install.
I will try to find out the cmdline cmd to install the sdk/ndk manually…

I checked the env vars,
echo $JAVA_HOME etc seems ok.

I wonder if the windows version would install under wine?

sdkmanager 'ndk;r27b' or replace with whatever version you need

Maybe your internet is bad?
I experienced this before.

I found this

Could you rm your ndk dir?

[EDIT -SEE END OF POST]

Ah ok, I think I was doing this a few months ago, deleting the ndk subdir.
It now goes back to
“Preparing"Install NDK 25.1.8937393”
— 50% configuring
and a clock timer with apparently nothing happening.
I gave up after 30 mins.

The connection is working, i ran firefox alongside and viewed pages, but its sometimes slow at 100-200k/s.

Maybe I will try:
sdkmanager ‘ndk;r25’
as suggested by LK, but i dont know if that version is accurate.

I did see:
https:/dl.google.com/android/repository/android-ndk-r29-beta1-linux.zip
as a download when trying to setup studio before, maybe just unzipping the right version there would work??

I see:
android {
ndkVersion “25.2.9519653”
}
at:
https://github.com/android/ndk/wiki/Unsupported-Downloads
(I don’t know why it choosing an old version.)

I might experiment with a wine64 install for this, the windows sdkman seems a bit more advanced.

It has to be said to google, if you do create a curated installation process for your software, you need to give much better error messages than this!

As Ammar said in another thread, we really need fully OSS versions of these tools.

building an SDL app for Android should be as simple as:
cc prog.c -o prog.exe -lSdlAndroidLib

STOP PRESS: while writing this, after 40 MINUTES with no indication of any progress, it came alive and started unzipping downloads! I just assumed the thing had crashed, no %progress given or anything!! it didnt even say “Downloading xxxxx”…

It now works, in that it builds the apk.
I have an old phone connwcted with developer options and usb debugging, just figuring how to run the app…
Thanks everyone!

the app developer decides which version… :slight_smile:

Good.
It should be signed with a debug key and automatically installed if you run ./gradlew installDebug make sure your phone is connected and USB debugging is enabled and you can run adb shell (you may need to allow your PC on your phone)

If you run ./gradlew assembleRelease the apk will be built at app/build/outputs/apk/release/ but you will need to sign it first with your signing key before installing.

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.

ie, the game.zip file above is 250Mb unzipped, (now gone!) but what files and folders could just be replaced with links into the sdk/ndk? (Then have a script which does that)

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…

Change all icons in those directories

./android-project/app/src/main/res/mipmap-xxxhdpi
./android-project/app/src/main/res/mipmap-xhdpi
./android-project/app/src/main/res/mipmap-mdpi
./android-project/app/src/main/res/mipmap-hdpi
./android-project/app/src/main/res/mipmap-xxhdpi

Each icon in those directories show up on different devices depending on the density of the pixels on the screen.

You can use android-studio Image asset to generate all icons, but you can also use this GitHub - ankit417/android-icon: Generate mip map icon resources for android from command line

To change the app name open android-project/app/src/main/res/values/strings.xml in any text editor you like.
Change the string app_name to any string you like.
like this

<resources>
    <string name="app_name">SCONNEX</string>
</resources>

You can replace the SDL folder with a git submodule linking to the SDL library.
SDK/NDK are installed on your system.

On Linux it just compiles your code and link it to libSDL2.so, which may be installed on your system, but on android it bundles libSDL2.so in your apk.
and since you have enabled arm64-v8a and armabi-v7a it compiles your code and SDL twice, one for arm64-v8a and one for armabi-v7a, and bundle both builds in the apk.

Learn OpenGL.

Just post the source code.

Make a repository including the code inside game.zip.
Don’t forget to make a git submodule linking to SDL.
and don’t forget to checkout the commit of SDL-2.32.2 as this is the only version that would work with the android-project directory.
if you want to update your SDL library, download the source code of the version you want and use the android-project directory that comes with it.


I forgot to mention that your game assets is in this directory.
android-project/app/src/main/assets

Btw I’m thinking about making a cross-platform, multiplayer, opensource game after I finish my exams.
Do you want to collaborate ?