ZeroMQ build for Android

Introduction : JeroMQ for Java

This page was originally helping to build and cross-compile JZMQ using a JNI bridge to the native library.
The process is risky, difficult, bad for code portability; only use it if you have very specific needs and strong reasons to do so.

For everybody using Java, especially with Android, it is STRONGLY recommended to use the pure-java implementation of ZeroMQ : JeroMQ instead.

According to many benchmarks it is also faster than using a JNI bridge.

Advanced users : Native build of JZMQ

This page will explain you how to build ZeroMQ along with Jzmq and its JAR, to be directly usable in Android and loaded into an APK file. It gives some preliminary solution for pyzmq as well.

The tutorial will be divided in two parts: one for ZeroMQ > 3.0 (where libuuid is no longer a dependency, thus making the whole process a lot easier) and another one, kept for reference, that will explain how to cope with older versions. For info where to put the final files in Eclipse, read the part Final thoughts at the end of the article.

The disable-version, enable-static and disable-shared flags ensure you'll generate a single libjzmq.so binary without version information, which is required to embed it into an APK. On newer systems, the parameter 'LIBS="-lpthread -lrt"' produces errors and has to be omited, because these librarys are already included.
If you're having problem on java environment, which will cause the configure failed with 'configure: error: cannot find zmq.h' or similar jni.h not found error , try to export the JAVA_HOME into your PATH environment:

Final thoughts

You should only have to take the built zmq.jar, place it in your application's in the libs/ folder. Add it to your build path in Eclipse if you're using Eclipse; ant should detect it nicely.
Then take the libjzmq.so file and put it in the libs/armeabi/ folder of your application, if your target has been armeabi since the beginning. Some users may want to put it in the armeabi-v7e folder instead.
Build your project with Eclipse or Ant, and it should work fine.

Remember that you will often have to activate special permissions to your app, for instance the android.permission.INTERNET for ZeroMQ's tcp transport protocol.

As a last word, if the generated binary us too huge (between 2.3 and 2.7 Mb) a good move is to strio/optimize it. To be straightforward, that means at least running

arm-linux-androideabi-strip --strip-all libjzmq.so

which reduces the binary size to about 600Kb, but you can also gain a few more Kb if using -ffunction-sections -fdata-sections -Wl,—gc-sections as additionnal CPPFLAGS.