Follow the instructions below to build SDL, SDL_ttf, TGUI and the example code for Android.
This guide has only been tested on Linux.
The build system for android doesn’t actually use cmake, but Config.hpp needs to be generated by cmake before you can build TGUI. Note that you will need a clean TGUI folder to build for android, you can’t use the same TGUI folder to build for both your host OS and android (even if you use separate build folders).
Create a new “build-null” folder inside the TGUI root folder. From inside that folder, execute the following:
cmake -DTGUI_BACKEND=Custom -DTGUI_CXX_STANDARD=14 -DTGUI_BUILD_GUI_BUILDER=FALSE ..
This will generate the required files. You can delete the “build-null” now, the contents of that folder isn’t needed.
Next to the gradle.properties file, create a new “local.properties” file. This new file should contain 2 lines, specifying the location of the android SDK and NDK:
The example project also builds SDL and TGUI, but you need to create symbolic links to those libraries so that the example knows where to find them.
Make sure you have SDL and SDL_ttf downloaded (for SDL 2 and NOT for SDL 1.2) and then run the following commands inside the app/jni folder:
ln -s /path/to/SDL SDL ln -s /path/to/SDL_ttf SDL_ttf ln -s /path/to/TGUI TGUI
Because the Android.mk file in app/jni will search for Android.mk files in all subdirectories, these links will cause it to find the files from SDL, TGUI and the example (in the src folder).
Currently the Android.mk file in the root of the TGUI folder expects to find the SDL folders next to the TGUI directory. If you have SDL installed somewhere else then you will have to manually fix the value of the SDL_PATH and SDL_TTF_PATH properties in that file.
Inside app/build.gradle you can change compileSdkVersion, minSdkVersion and targetSdkVersion to the wanted values. If you change minSdkVersion then you must also change the APP_PLATFORM argument in the same file.
To choose the architectures to build, change the abiFilters property in app/build.gradle. The final .apk will contain all those architectures and can be installed on devices that support any of them.
From inside the android-sdl folder, execute the following command to build everything. This will build any changes to SDL, TGUI and the example for all architectures and bundle everything into a single apk file.
If you have an emulator or device connected then you can install the apk with the following command:
If the application crashes, you should run “adb logcat” and look for log output that shows the reason of the crash.
If the program exits due to an exception being thrown then you will find a line like this in the output followed by the error message:
"terminating with uncaught exception of type tgui::Exception:"