Using Smack xmpp lib on Android with Netbeans

Android + XMPP + Netbeans

Last week i got my Android phone and finally started coding for a mobile phone (which really is a great experience and lot’s of fun).

During my daylight work i’m using xmpp in different projects and tools and so i would really like to use it on the Android phone also. In the java world there is a really neat library called smack from ignite realtime which makes using xmpp a piece of cake and so i asked myself if it would also run on android?

Yes it does…BUT…you need a patched version that i found on the net…
In Eclipse it seems to be easy to link a external library to a android project but in Netbeans i was not so intuitively as i thought…
You need three little steps to include a external library like smack and here they are:

#1 STEP:

Create a local folder named „lib“ in your Android project folder like this:

lib folder in project directory

Now copy the patched smack.jar file into this folder.

#2 STEP:

Add the jar file to your libraries in netbeans like this:

add smack.jar to project libraries

#3 STEP:

At last you have to edit the build.xml file of your android project and add the link to the /lib folder where you copied the library file.

Add the following to the end of your build.xml file:

<!– Add path to external libs to buildpath –>

<target name=„-pre-jar“>

<property name=„external.libs.dir“ value=“/PATH_TO_YOUR_PROJECT/lib />

<copy todir=„${build.classes.dir}“>

<fileset dir=„/PATH_TO_YOUR_PROJECT/lib/>



That’s it…

Now you should be able to use the external library in the same way as you know it from your normal desktop machine.
Be aware that the patched smack.jar does not contain the complete functionality of the desktop version…

You might also take a look at a project called asmack which you could find here