Perita

Heaps and HashLink on Android

Despite what i said in the last post, that we did not agree on whether to develop Xenorogue as an Android game, i always wanted to at least try to design the game for smartphones, and only in the case that we could not do it, then release it just for PC. In particular, i did not want to use a virtual D-pad, like we did with MLRL, and my intention was to embrace as much as possible the touch-screen interface that smartphones use.

In order to do that, i need first to build an Android version of the game to try it on real hardware and have a “feel” of how it could play. Although i never tried it before, i knew that it was possible to compile Haxe applications to Android using the HashLink target, Heaps’ documentation explicitly lists Android as a supported platform, and i believe this is exactly how the mobile version of Dead Cells is built, for instance.

Years ago i already published a couple of games with SDL2 to Google PlayAmoebax and Prison Break, although they are no longer available on Google Play—, so it was not my first rodeo, as they say, however i almost completely forgot how it was supposed to be done, rendering my supposed experience useless.

Therefore, i had no other option than to start from scratch: I took CircleCI’s Docker image for Android NDK as base, as i already knew that i would need a Docker image in order to build the APK with GitLab’s CI, perused SDL’s documentation regarding its Android port, and built their testgles.c sample application. To SDL’s credit, the process went very smoothly and i ended up with a working APK on my first try.

My next step was to try to compile HashLink. Oh, i did search before trying it myself, and already found a repository to build Heaps for Android, but it is out of date and no longer builds, that’s why i had to do it “my way”: create the Android.mk file based on their CMakeLists.txt to build HashLink as a dynamic library, try to compile it, and fix as best as i can all the errors that the compiler throws at me. Rinse and repeat for all of HashLink’s dependencies.

It took me almost the whole morning, but by noon i could build and run Xenorogue on the emulator. I was beside myself with joy. That is, until i remembered that i had edited Haxe’s generated C code to remove the references to OpenAL’s functions and make my job a bit easier; to be able to build the whole thing with a GitLab’s CI pipeline i had to build OpenAL too.

This part took a surprisingly big chunk of my afternoon. It is mostly my fault, because recent versions of OpenAL Soft are written in C++ with exceptions, that are disabled by default with ndk-build, i remembered that there was a good reason for that but did not bother reading the documentation that this is no longer the case, and instead went back to the last tagged version of OpenAL Soft written in C. I am still not sure whether i built it properly, because there are some scary-looking warnings regarding different sized symbols when linking the library, but i do not use audio for now and will cross that bridge when i come to it.

In short, now i have a Docker image that can successfully build and package Xenorogue for Android on every commit.

Screen shot of the current version of Xenorogue running on an Android emulator

Cool!