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 github.com/mgerhardy/sdl-android-example 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-setupThis 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:
. ~/.bashrcNow you are ready to run
makeThis 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 MyAwesomeGame.java. 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; doneNow 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 Android.mk file.
mv android-project/src/org/myawesomegame/ android-project/src/org/mygame
mv android-project/src/org/mygame/MyAwesomeGame.java android-project/src/org/mygame/MyGame.java
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.