Monday, December 3, 2018

Installing JeroMQ for Android Project


I've found that ZeroMq is an amazing library for authoring distributed systems.  Cross compiling ZeroMq for Android devices, while feasible, is highly unrecommended.  The general guidance is to instead use JeroMQ (a Java-native compatible library).  This post will outline how to configure it and install it into a simple Android project.

Let's start by snagging the latest release version:



$ wget https://github.com/zeromq/jeromq/archive/v0.4.3.tar.gz


Uncompress the package:


$ tar -zxvf v0.4.3.tar.gz


Build the library:


$ cd jeromq-0.4.3/

$ mvn package

...

[INFO] Building jar: /var/tmp/jeromq-0.4.3/target/jeromq-0.4.3-javadoc.jar

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 03:31 min

[INFO] Finished at: 2018-02-22T19:39:18-06:00

[INFO] Final Memory: 37M/444M

[INFO] ------------------------------------------------------------------------

lipeltgm@kaylee:/var/tmp/jeromq-0.4.3$



Locate the generated Java libraries:


lipeltgm@kaylee:/var/tmp/jeromq-0.4.3$ find . -name "*.jar"
./target/jeromq-0.4.3.jar
./target/jeromq-0.4.3-sources.jar
./target/jeromq-0.4.3-javadoc.jar
lipeltgm@kaylee:/var/tmp/jeromq-0.4.3$ 

Copy the proper library to your Android project:


$ cp /target/jeromq-0.4.3.jar ~/AndroidStudioProjects/App01/app/lib


Test Usage of Library in IDE


package com.fsk.app01;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Socket;
import org.zeromq.ZMQ.Context;



public class MainActivity extends AppCompatActivity {

  private ZMQ.Context context_=null;

  private ZMQ.Socket socket_ = null;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    context_ = ZMQ.context(1);
    socket_=context_.socket(ZMQ.REQ);  }

}



And now my friend you have the basis for doing some really cool stuff with ZeroMq in your Android application.

Cheers.

No comments:

Post a Comment