We can setup Mqtt client library paho in two ways.
A. From binaries
B. From Source
A. From binaries
1. We need two jar files for setting up the mqtt client library in Android Studio
a. Mqtt client library
b. Mqtt Service library
These library files can be dowloaded from here https://repo.eclipse.org/index.html#welcome
2. Copy the downloaded files to libs directory of the Android project
3. From Android studio, right click on each jar file and click “Add as Library”
4. Now the project is ready for using the Paho library
B. From Source
1. Download the latest version of the paho libraries from the given below link
http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git
eg : http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/snapshot/org.eclipse.paho.mqtt.java-1.0.2.tar.gz
2. Extract the tar.gz file
3. Change directory to org.eclipse.paho.client.mqttv3
$cd org.eclipse.paho.client.mqttv3
4. Execute the given below commands
$mvn compile $mvn package
5. Output of the above commands is a jar file ( org.eclipse.paho.client.mqttv3-1.0.2.jar
) in the target directory
6. Copy the jar file org.eclipse.paho.client.mqttv3-1.0.2.jar
to the libs
directory of Android project
7. Next we need to compile android service
8. Change directory to the service directory
$cd org.eclipse.paho.android.service/org.eclipse.paho.android.service
9. Open the pom.xml file and add the given below code just above dependencies
tag
<repositories> <repository> <id>Eclipse Paho Repo</id> <url>https://repo.eclipse.org/content/repositories/paho-releases/</url> </repository> </repositories>
10. Execute the given below commands
$mvn compile $mvn package
11. Output of the above command is a jar file ( org.eclipse.paho.android.service-1.0.2.jar ) in the directory target
12. Copy the jar file into libs directory of the Android studio projects
13. From Android studio, right click on each jar file and click “Add as Library”
14. Now the project is ready for using the Paho library
Comments on this post