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.
-
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.jarI got a nice jar library in the folder. I added that jar to my
project usingRIGHT_CLICK->Properties->Java Build Path->Add External JarsThen 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) -
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 usingRIGHT_CLICK->export->java->Jar FileThen 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?
Well I got it working myself..
Use the first method I mentioned in the question, you will get a jar
file in the path
not already there)
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?