Android: using the java socket.io client from Gottox in an Android application

Well, I am writing an Android application, and I want to use the Socket.IO-Client for Java , written by Gottox. The documentation on github says the library is compatible with Android.

Now my question is somewhat basic. How to use this library in an Android app?

So far I have tried two methods.

  • I built this library's jar file using commands (as explained in the doc library)

    cd $PATH_TO_SOCKETIO_JAVA ant jar ls jar/socketio.jar 

    I have a nice banner library in a folder. I added that jar for my project using

     RIGHT_CLICK->Properties->Java Build Path->Add External Jars 

    Then I connected using

     SocketIO socket = new SocketIO("http://"+ip+":"+port+"/"); 

    I was able to compile and create the application without any errors. But when I run, I got an exception in the line that I posted above.

     java.lang.NoClassDefFoundError: io.socket.SocketIO at com.research.socketioresearch.LoginActivity.connectToSocketIO(LoginActivity.java:122) at com.research.socketioresearch.LoginActivity$1.handleMessage(LoginActivity.java:113) 
  • As a second attempt, I created a java project using socket.io library source code in my eclipse. Then I exported this project as a jar using

     RIGHT_CLICK->export->java->Jar File 

    Then I added this jar file to my original android project, using the same way as I tried in method 1 (Add external banks). This time, I was also able to compile and build, but get the same exception in a single line of code.

Now who has success in using the same library in Android? How it's done?

+4
source share
1 answer

Well, I earned it myself.

  • Use the first method that I mentioned in the question, you will get the jar file in the path

     PATH_TO_SOCKETIO_JAVA/jar/socket.jar 
  • Now in your Android project, create a folder called "libs" (if it is not already)
  • Copy this jar file to the 'libs' folder.
  • Go to eclipse and update your Android project.

I'm still not sure why adding a jar file using the "Add External Banks" button in the project properties does not work. How to add a library to a project?

+1
source

All Articles