Android : using java socket.io client from Gottox in android app

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

Now my question is somewhat basic. How to use that library in an android app?

So far I have tried two method.

  1. I built a jar file of that library using the commands (as explained in the library's doc)

    cd $PATH_TO_SOCKETIO_JAVA
    ant jar
    ls jar/socketio.jar
    

    I got a nice jar library in the folder. I added that jar to 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 build my app without any errors. But when I run I got an exception on the line I have 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)
    
  2. As a second try, I created a java project using the socket.io library source code in my eclipse. Then I exported that project as a jar file using

    RIGHT_CLICK->export->java->Jar File
    

    Then I added that jar file to my original android project using the same way I tried in method 1 (Add external jars). This time also I was able to compile and build, but getting the same exception at same line of code.

Now anyone has success in using the same library in android? How it is done?

Answers


Well I got it working myself..

  1. Use the first method I mentioned in the question, you will get a jar file in the path

    PATH_TO_SOCKETIO_JAVA/jar/socket.jar
    
  2. Now in your android project, create a folder called "libs" (if it is not already there)
  3. Copy that jar file to the 'libs' folder.
  4. Go to eclipse and refresh the android project.

I am still not sure why adding jar file using "Add external Jars " button in project properties is not working. Both add library to the project right?


Need Your Help

Is there any secure way to create a user session in a SPA with a Basic Auth REST API?

angularjs rest session authentication basic-authentication

I need to build a Single Page Application based on AngularJS that will retrieve data from a REST API. Those REST services are secured using Basic Auth + HTTPS.

Adding pages/posts after plugin installation

wordpress wordpress-plugin

There are a few plugins that I know that after installation they will create pages or posts. How do you do this?