How to build tgui on android

Started by Alexhero, 03 February 2021, 17:23:22


I've just read your tutor about building tgui on android and I don't actually understand how to do it. I have already installed and built sfml in android studio, but I dont know what to do next. Help me pls((( It is my first time doing this


What OS are you using? The commands that are given have to be run on the command line and might be slightly different on platforms other than linux.

I can't give you a better guide than what the tutorial contains, but if you get stuck on specific things or don't understand some of the instructions then I might be able to clarify that part.
The first step if just running cmake. You can use the graphical cmake interface if you prefer, "-DCMAKE_SYSTEM_NAME=Android" in the command would mean to create a CMAKE_SYSTEM_NAME property and set its value to "Android".



I'm not sure where you are stuck.
How did you build SFML? The instructions are very similar. I could try to explain in more detail how to run cmake, but didn't you already have to do that for SFML as well?


The thing is that the SFML itself was built for me and I don't actually know how to use cmake for building libs like this :) I'm sorry))
I can tell you exactly how I tried to build it (I mean tgui itself). I was using a cmake graphical interface and to be honest I dont know how to use it properly, so could you help me? Also, I dont know where to find these variables (which was written about in your tutor).


I wouldn't use the graphical interface actually, unless you already know how to use it. For building TGUI for windows it is fine because all properties exist, but for Android you need to start manually creating properties, so I find using the command line easier.

On linux you have the "make" command, but on Windows you will need some kind of build system installed. Do you have either Visual Studio or MinGW installed? The guide below will assume you have Visual Studio 2019, if you have a different version then have a look at for what you need to pass behind the "-G" in the cmake command.

I haven't tried the follow the following instructions, so there may be errors in it, but you should do something like this:

- Create a new "build-android" folder inside the TGUI folder you downloaded.

- Open a command prompt. (Press Win+R and type "cmd.exe" without the quotes to start one)

- Navigate to your TGUI folder in the command prompty.  (e.g. if TGUI is located in C:\TGUI then type "cd C:\TGUI\build-android" without the quotes and hit enter)

- Run the following cmake command in the terminal. Make sure to replace "/path/to/ndk" with the path to the NDK (which is probably part of your Android Studio installation).
cmake -G "Visual Studio 16 2019" -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK=/path/to/ndk -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Debug ..

If it all goes well then there should be a Visual Studio project in the build-android folder which you can open and build. That will produce the libraries.


I've got this kind of error, it happens either for x86 and arm64-v8a. I did all as you said, where could be a problem here? I guess, I did something wrong with the VS


Was there a .sln file in the build folder? I think you just opened the wrong file.

Check if there is a .sln file next to the .vcxproj file and open that one with Visual Studio.


This happens when I'm trying to build it using cmake


I have no idea about that.

Does it give you the same error if you remove the "-A Win32" from the command?

If that doesn't work then you could try installing MinGW-w64 (
You would then need to change the "-G" parameter in the cmake command from "Visual Studio 16 2019" to "MinGW Makefiles".
If the cmake step would finish with MinGW then you probably have to run "mingw32-make" and "mingw32-make install" afterwards (this is the equivalent step to building the project with Visual Studio and also building the INSTALL target in visual studio).

I don't have android tools installed on my windows, so I currently can't do any tests. I will probably be able to try building on Windows myself this weekend.


I did some tests and some reading, you can't really use Visual Studio for this.

If you have MinGW installed then you can use that, otherwise you can download Ninja (which is a single executable that you can place anywhere you want, so it is a lot less than having to install the entire MinGW package just to use a small part of it). To download ninja, get "" from

I had to make the following changes to the cmake step:
- Delete the contents of the build directory that you already created, you need to start a fresh build.
- I had to use CMake 3.19, when using CMake 3.18 it would look for android stuff in the wrong directory
- Pass "Ninja" as parameter to the "-G" flag (use "MinGW Makefiles" when using MinGW)
- When using ninja, set CMAKE_MAKE_PROGRAM to the executable location. The same applies for MinGW and mingw32-make.exe, but MinGW is probably installed in the PATH which makes this step unnecessary.
- I had to use slashes in the android NDK path, it didn't like the backslashes (it was interpreting them as escape characters, so using "\\" instead of "/" would probably work as well).

This is the command I used:
cmake -G Ninja -DCMAKE_MAKE_PROGRAM="D:\Downloads\ninja.exe" -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK="C:/Users/texus/AppData/Local/Android/Sdk/ndk/22.0.7026061" -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_BUILD_TYPE=Debug ..

At this point for me it complained about not finding SFML because I currently don't have the SFML android libraries installed. If you have SFML installed in your NDK then it should find them automatically (at least it does on linux).
I will try building SFML tomorrow and see if there are any more difficulties to solve in getting TGUI's android build working on windows.

Assuming it find the SFML libraries for you and the cmake step completes, you would probably have to run "ninja" and "ninja install" to create the libraries and installing them to the NDK (you will likely need the entire file path to the ninja executable instead of just writing "ninja").


I looked into building SFML, but it still has its issues.
SFML 2.5.1 had 2 issues that prevented me from using it on android in the past.

The first one caused a crash at runtime and has been solved recently (3 weeks ago), so the latest version from github should be able to run on android (but I haven't tested it yet).

The second issue, which still exists in the latest github version, is that it doesn't support NDK 22 (which you are using). There is a workaround to make it work, but it does raise the question: what NDK version were your SFML libraries compiled for?
The TGUI libraries must be compiled with the exact same version of the NDK. If someone just gave you SFML libraries and you are then going to build TGUI libraries yourself, then they may not match and your program will most likely just crash (if it doesn't already fail when linking).

There is also a third issue for some people: SFML has no support for 64-bit platforms, which means you can't publish your app in the App Store.


If you are still interested in trying SFML and TGUI on android then I've build some libraries that you should be able to use.

Download:  (42.3 MB)

The zip file contains an "sfml" and a "tgui" folder. These folders need to be placed in "C:/Users/Alexhero/AppData/Local/Android/Sdk/ndk/22.0.7026061/sources/third_party".
They contain debug libraries for both x86 and armeabi-v7a.

(I only build the libraries, I didn't try to run a program with them)