Compiling ZeroMQ library for Android Applications on Intel x86 Platforms

By Promotion Published Date
28 - Jul - 2015
| Last Updated
28 - Jul - 2015
Compiling ZeroMQ library for Android Applications on Intel x86 Pl...


ZeroMQ is an open source library widely used by programmers around the world. Its Wikipedia definition is as follows: “ZeroMQ (also spelled ØMQ, 0MQ or ZMQ) is a high-performance asynchronous messaging library aimed at use in scalable distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker. The library is designed to have a familiar socket-style API.”

On ZeroMQ’s website, the community has provided build instructions for the Android platform ( However, those instructions are focused on ARM* architecture, and developers will meet build failure when they try to build the x86 version of ZeroMQ library by following the instruction step by step. That is why this article has been written.

Build Environment Preparation

The first goal in building ZeroMQ is to create a separate standalone tool chain for x86 that relies on Android NDK.
1. Download and install the latest Android NDK from: In this article we use android-ndk-r10d-linux-x86_64.
2. Fix a known issue in, by applying the patch mentioned in Without this patch the build will fail in the next step.
3. Generate a standalone tool chain for the Android x86 platform.
./home/xxx/android-ndk-r10c/build/tools/ --arch=x86 --toolchain=x86-4.9 --install-dir=/home/xxx/android-standalone-toolchain-x86

You should follow the next two suggestions to avoid unexpected build problems:
1. Generate a single x86 tool chain in a separate directory. Don’t mix the x86 tool chain and the ARM tool chains in one directory.
2. Install the standalone tool chain in your /home directory, to help avoid root/no-root authority issues.
4. Configure the environment variables.
export PATH=/home/xxx/android-standalone-toolchain-x86/bin:$PATH export OUTPUT_DIR=/home/xxx/tmp/zeromq-android

Build ZeroMQ for Android x86

The following steps will show you how to build ZeroMQ along with Jzmq and its adjoining JAR, to be directly usable in Android and loaded into an APK file.

1. Download the source code and build ZeroMQ 3.x.
mkdir /home/xxx/tmp cd /home/xxx/tmp git clone cd zeromq3-x/ ./ ./configure --host=i686-linux-android --prefix=$OUTPUT_DIR LDFLAGS="-L$OUTPUT_DIR/lib" CPPFLAGS="-fPIC -I$OUTPUT_DIR/include" --enable-static --disable-shared LIBS="-lgcc" make make install
2. Download the source code and build jzmq.
cd /home/xxx/tmp git clone cd jzmq/ ./ ./configure --host=i686-linux-android --prefix=$OUTPUT_DIR LDFLAGS="-L$OUTPUT_DIR/lib" CPPFLAGS="-fPIC -I$OUTPUT_DIR/include" --disable-version --with-zeromq=$OUTPUT_DIR LIBS="-lpthread -lrt" make make install 
If you see a failure during the execution of “./configure”, remove LIBS="-lpthread –lrt" and try again.
3. Copy and zmq.jar files to your desired directory, and now ZeroMQ has been built successfully!
cp /home/xxx/tmp/zeromq-android/lib/ /home/xx/tmp/ cp /home/xxx/tmp/zeromq-android/share/java/zmq.jar /home/xx/tmp/

An example using ZeroMQ in Android x86

You can now start using ZeroMQ in your Android applications. Here is a simple step-by-step example that describes how to use ZeroMQ in implementing message interaction between the ZeroMQ client and the ZeroMQ server. Some of this sample code is from the ZeroMQ official guide and wrapped into the Android project.

1. Copy into the directory “DemoJZMQ/jni/”, and copy zmq.jar into the directory “DemoJZMQ/libs/”.
2. Add the script below to
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libjzmq LOCAL_SRC_FILES := include $(PREBUILT_SHARED_LIBRARY)
3. Add the script below to
APP_ABI := x86
4. Implement the server side function.

01  public void startZMQserver() throws Exception {

02 ZMQ.Context context = ZMQ.context(1);


04 // Socket to talk to clients

05 responder = context.socket(ZMQ.REP);

06 responder.bind("tcp://*:" + SERVER_PORT);


08 printLog("Server", "Started");

09 while (!Thread.currentThread().isInterrupted()) {

10  // Wait for next request from the client

11 byte[] request = responder.recv(0);

12 printLog("Server", "Received:" + new String(request));


14 // Do some 'work'

15 Thread.sleep(1000);


17 // Send reply back to client

18 String reply = "World";

19 responder.send(reply.getBytes(), 0);

20 printLog("Server", "Response send.");

21  }

22 responder.close();

23 context.term();


5. Implement the client side function.

01  public void startZMQclient() throws Exception {

02 ZMQ.Context context = ZMQ.context(1);


04 // Socket to talk to server

05 printLog("Client", "Connecting to ZMQ server…");


07  requester = context.socket(ZMQ.REQ);

08 requester.connect("tcp://" + SERVER_IP + ":" + SERVER_PORT);


10 printLog("Client", "Connected to server.");

11 for (int requestNbr = 0; requestNbr != 10; requestNbr++) {

12 String request = "Hello";

13 printLog("Client", "Sending Hello " + requestNbr);

14 requester.send(request.getBytes(), 0);


16 byte[] reply = requester.recv(0);

17 printLog("Client", "Received " + new String(reply) + " "

18 + requestNbr);

19  }


21  context.term();

22  }

6. Run the example app on a device, click the “start server” button first, and then click “start client”. From “adb logcat” you can see the execution results (Figure 1) that show when the client sends a “Hello” to the server, the server responds “World” back to the client 10 times.


This article describes how to compile the ZeroMQ library for the Android x86 platform step by step. Also provided is a simple example using message transfer to show how to use ZeroMQ in Android applications. As mentioned above, the key point in compiling ZeroMQ for x86 successfully is to generate correct standalone tool chains for x86 based on the Android NDK. This method will be useful for not only ZeroMQ, but also for other 3rd party library builds.

For more such Android resources and tools from Intel, please visit the Intel® Developer Zone