Cross build libmosquitto static library for Android


I’m trying to cross-build the mosquitto library for Android - I am building (as part of a Godot game engine installation) support for MQTT client. The static library builds fine under Linux (Ubuntu) with openssl 1.1.1 but as part of the cross-compilation process within Godot is the rebuild of Android templates to include user included libraries - in this case libmosquitto. There is a comment in the changelog saying there were changes a long time ago so it will build for Android but I can’t find anywhere how to do this?

Can anyone help me here?


I’ll answer my own question so it helps anyone else - I downloaded the openssl library for the same basis and in the NOTES.ANDROID file there is the necessary setup which is quite simple;

export ANDROID_NDK_HOME=/home/chris/Android/Sdk/ndk/21.4.7075529
./Configure android-arm64 -D__ANDROID_API__=22
make clean

I save that as a re-usable script and used it for building openssl and mosquitto, Other than the paths for a different version of the NDK the only thing I added was “make clean” which I found was necessary if you’d already built a previous version for a different platform


spoke too soon - it just builds for linux still! doh!

will keep trying…

I’m afraid I can’t help much - the contribution which fixed building on Android was in the code, not in the build part. I don’t know how the person doing it was actually doing the build.



OK got it building now for all Android platforms and Ubuntu 21.10 (both from latest sources and supposedly the same version that’s currently in 21.10 (version 2.0.11) - however neither works with openSSL (which I’m also building from similar dated versions 1.1.1o and 1.1.1k from last year). The only error I see when building is one of the plugin examples;

make[2]: *** [plugins/message-timestamp/CMakeFiles/mosquitto_message_timestamp.dir/build.make:103: plugins/message-timestamp/] Error 1

It builds fine on Linux but fails on Android (all versions).

However, when connecting to HiveMQ which requires a TLS connection it always throws a “Error: A TLS error occurred.” - I have also tried the change from;

in both versions of openssl (1.1.1o and 1.1.1k) and mosquitto (latest and 2.011)
but that hasn’t changed anything - when running the newly built command line tools (mosquitto_pub and mosquitto_sub) I still get the TLS error despite giving the --insecure and/or —tls-use-os-certs.

Any ideas?