Build SDL2_ttf for android

I’m building simple SDL2 test programs for android. SDL2_image has been built just fine but i can’t build SDL2_ttf. I’m using cmake as the build system but no matter what i do, the build system doesn’t find freetype. I have already executed download.sh in the external/ folder of SDL2_ttf and the source files of freetype and harfbuzz are available in their respective directory. The find_package(Freetpe REQUIRED) statement of CMakeLists.txt under SDL2_ttf fails. So what can i do? Any help would be appreciated.

This probably doesn’t help you, but I’m not having any problems building SDL2_ttf in Android Studio.

But my whole point was to not use android studio. Okay i’d try building using android studio and would let you know.

@rtrussell Look I got the same error in android studio too. Freetype is not found. How did you build yours? Can you elaborate?

I’ve just compared my project with the contents of SDL2_ttf-2.20.2.zip and it is noteworthy that my project has a freetype directory whereas the Zip file hasn’t (otherwise they look very similar).

I can’t remember now where that freetype folder came from (possibly an earlier release of SDL2_ttf), and I haven’t tried deleting it to see if it is essential, but perhaps that is related to your issue.

Edit: Drilling down a bit further, both my project and the Zip contain external/freetype and external/harfbuzz directories so that is probably a red herring; the freetype directory in my project may well be a hangover from an earlier release of SDL2_ttf which was organized differently.

@rtrussell Can you somehow send me your version of SDL2_ttf that has working freetype and harfbuzz in it? Like an empty working project that makes use of SDL2_ttf. I have spent 2 days fruitlessly.

I’m afraid I haven’t got anything suitable.

SDL2_ttf is a single .c file (and a .h file), one alternative is to simply copy that in your project and then just also link to freetype by hand.

Building for Android with the CMake file SDL2_ttf has already should indeed use the FreeType and harfbuzz that are included in the package in the external directory - but if you don’t want to read that CMake file, which is needed to understand how that works, my suggestion is simply to craft your own in your own project.

@rtrussell @eri0o I solved the problem by putting the following lines in app/jni/CMakeLists.txt:

set(SDL2IMAGE_INSTALL OFF CACHE BOOL "" FORCE) 
set(SDL2IMAGE_SAMPLES OFF CACHE BOOL "" FORCE)
set(SDL2TTF_INSTALL OFF CACHE BOOL "" FORCE)
set(SDL2TTF_SAMPLES OFF CACHE BOOL "" FORCE)
set(SDL2TTF_VENDORED ON CACHE BOOL "" FORCE)
set(SDL2NET_INSTALL OFF CACHE BOOL "" FORCE)
set(SDL2NET_SAMPLES OFF CACHE BOOL "" FORCE)
set(SDL2MIXER_SAMPLES OFF CACHE BOOL "" FORCE)

option(BUILD_DIGIVICE "" ON)
1 Like

Great work, thanks for reporting the results here!

1 Like