SDL2 and Android

This is going to become yet another guide for building SDL2 based games for Android and writing a simple application for it. I assume you are on a *nix system.

There are several steps that must be done in order to be able to compile and run everything.

First of all you should clone the template I've created in order to set everything up.  It's available at and includes everything you need for SDL2 and Android development.

First of all we have to set up the android sdk and ndk installations. To achieve this, you should enter the sdl-android-example directory and type
make android-setup
This will download the ndk and sdk archives, extracts them and put them into your path (~/.bashrc). So in order to let the new environment variables work for you, type the following:
. ~/.bashrc
Now you are ready to run
This will create the android projects and compile the SDL sources with some placeholder C++ file.

All you have to do now is to replace all the MyAwesomeGame and myawesomegame strings with your game name, add your C or C++ sources and extend You can use the following shell commands to do this quite quickly (assuming that your new game name is MyGame):
for i in $(find . -type f); do sed -i 's/MyAwesomeGame/MyGame/g' $i; sed -i 's/myawesomegame/mygame/g' $i; done
mv android-project/src/org/myawesomegame/ android-project/src/org/mygame
mv android-project/src/org/mygame/ android-project/src/org/mygame/
Now add your C++ source code files to the src folder. They must have the extension cpp in order to get included automatically. If you create new subdirectories or another extension, you have to adjust the file.

There are some targets in the Makefile that might help you to get some stuff behind the Android build. It's worth to check it out.

Beliebte Posts