How to use Smack 4.1 in Android?
Asked Answered
B

1

25

I was looking at this answer Using your own XMPP server for android chat app (Smack API) to learn about the available XMPP APIs. Smack seems like a good choice.

Prior to Smack 4.1 one had to rely on aSmack. Starting with 4.1, Smack will run natively on Android. I have a couple of "getting started" questions.

Question 1:
How do I include Smack 4.1 in my Android project in Eclipse?
The instructions here https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide seem to be for Android Studio

Question 2:
Will the code stay the same for Android?
I am referring to their official documentation here: https://www.igniterealtime.org/builds/smack/docs/latest/documentation/index.html
What I would like to know is whether the usage of the API will stay the same in Android, too.

Blacken answered 17/11, 2014 at 4:25 Comment(5)
have a look github.com/fangzhen/androidxmppclientDemodena
@NaveenTamrakar I do not see how that relates to my question.Blacken
im-a-developer-too.blogspot.ca/2014/04/…Demodena
@NaveenTamrakar Those are different libraries, if I am not wrongBlacken
Both of them use old outdated (a)Smack libraries. One is even from 2008 (6 years old!).Catchy
C
28

How do I include Smack 4.1 in my Android project in Eclipse?

Like you would include any other Java library in Eclipse Android project. By putting the .jar files in the libs/ directory, the Android plugin of Eclipse and the Android Ant build system will make them available to the projects classpath and include them in the resulting .apk.

The thing with Smack 4.1 is, that it is heavily modularized. If you want a full featured Smack on Android you need something around 11 .jar files. Now, you could use Android Studio using gradle, this way including Smack as is simple as adding

dependencies {
  compile "org.igniterealtime.smack:smack-android:4.1.0-rc1"
  compile "org.igniterealtime.smack:smack-tcp:4.1.0-rc1"
  // optional features
  compile "org.igniterealtime.smack:smack-android-extensions:4.1.0-rc1"
}

and gradle will take care of resolving the transitive dependencies.

But, Android Studio, or the Android gradle plugin to be precise, does not support downloading and debugging with source attachments1. And this is something you clearly want when working with open source libraries.

That's for example one of the reasons I don't use the gradle plugin myself. I could not develop Smack then (I also like Eclipse, but that's a different story).

So we are back at working with Eclipse/Ant for our Android project. The Smack 4.1 README tells you to use the MavenToAndroidAnt Python3 script, which will automatically download the artifacts and delete the old ones on an update. If you hook it into your build process, it's nearly as good as using gradle but also supports source attachments.

Of course you could also add the 11 .jar files manually, but who wants to do that and have binaries in their source repository?

Will the code stay the same for Android?

Yes, starting with Smack 4.1, Smack is Smack. So you can refer to the same javadoc, no matter if you are on Android or not. Note that this was also true for aSmack, since it's just a port of Smack to Android.

1: Correct me if I'm wrong, but last time I tried it was not possible. The situation may got better in the meantime.

Catchy answered 17/11, 2014 at 10:17 Comment(6)
downloading and debugging with source attachments. What is that? :)Blacken
Basically: When the debugger is able to show the source of a library while stepping through it.Catchy
@Catchy I managed to get it working on my Android devices. The builder takes a long time (~3 seconds ) but its fast after that.Divorcement
@Catchy Hi, added three dependancies as you did in gradle file, but after sync, I'm getting Failed to Resolve error for all three dependancies. what to do?Krys
Hi, I am facing problems with smack 4.1 , please take a look #30256674Squeteague
How can we do Bosch connection in smack ? Any idea please help me !!Judsonjudus

© 2022 - 2024 — McMap. All rights reserved.