Getting Smack working with Android 1.5 SDK

I’m trying to build Smack from source using the Android SDK instead of the standard JRE so that I can use Smack in an Android application. The first thing I did was excluded the following, since they require AWT which isn’t included in the Android SDK:

smack.debugger.LiteDebugger

smackx.debugger.EnhancedDebugger

smackx.debugger.EnhancedDebuggerWindow

Once that is done all that is left with problems are:

smack.sasl.SASLGSSAPIMechanism

smack.sasl.SASLMechanism

smack.util.DNSUtil

smack.util.PacketParserUtils

These don’t work because the Android SDK doesn’t include the following:

javax.security.sasl

javax.security.auth.callback.NameCallback

javax.naming

java.beans.PropertyDescriptor

So my question is, does someone more knowledgable than me about these things and how they work think it’s possible to remove those dependancies without a massive amount of effort? I would assume some of them have Android equivilants, like javax.naming has to be replaced by something in Android…

An alternative, that I’m going to try next, is to see if I can pull out the source for those items from the JRE and rebuild them in my own namespace, then have Smack point to my custom built ones instead of the Java ones. However, I’m expecting that this will lead to the need for many other dependancies and / or there was a reason that the Android SDK left them out.

I got an e-mail from someone who did get Smack working on Android and they did it mostly by just removing stuff from Smack. I’m curious if someone with more knowledge of Smack could let me know what the ramifications of these changes are.

In **PacketParserUtils.java **the function **parseWithIntrospection **now just returns null when called. The reason for this is that PropertyDescriptor isn’t available to Android and including of it requires inclusion of most of java.beans, which is pretty substantial from what I can tell.

In SASLMechanism.java the member variable sc was removed (which requires a number of other changes, listed here). The assignement of sc in the authenticate functions was removed. In the parameterless version of the authenticate function the try/catch block was completely removed. In challengeReceived the if/else block was removed. The handle function still loops through the callbacks, but it just throws an UnsupportedCallbackException for each now.

In SASLGSSAPIMechanism.java props.put call and sc assignment was **removed **from both authenticate functions.

I pulled the code required for DNSUtil over from the JDK source tree and I’m going to look into pulling over the SASL code from the JDK as well to see if I can avoid removing all the SASL stuff next. The requirement of java.beans though is something that doesn’t look like it will be easy to fix with a few files pulled in from the JDK so if someone can comment specifically on that one (and whether or not I can just comment it out as above) it would be appriciated.

Once again the currently available XMPP clients available on Android devices are pissing me off so I am back to looking into writing my own. I’m planning on picking up where I left off but I would still greatly appreciate it if someone could answer any of my previous questions as it would save me a lot of time over answering them myself by pouring over XMPP RFCs and fully understanding the Smack source code.

I was able to pull about 500KB of code over from JDK and build a little supplemental library to extend Android with a few of the missing classes.

However, I was still left without java.beans.PropertyDescriptor and if I just have the function org.jivesoftware.smack.util.PacketparserUtils.parseWithIntrospection return null there are a couple of code paths that won’t handle things gracefully (and could cause problems later on).

What came next I am pretty sure will cause me to burn eternally in hell.

I grabbed PropertyDescriptor from the JDK and started bringing over it’s dependencies. Once I got to java.beans.Introspector I commented out almost the entire file except the one function called in it and it’s dependencies. I also went online and found an open sourced version of sun.reflect.misc.ReflectUtil.java and created my own version of it with just the functions being called and their dependencies. So basically I have not only ripped code strait out of the JDK and am dropping it into Android, but that code is now completely bastardized beyond recognition.

On the plus side, I now have Smack compiling for Android 1.6… the next step is to throw together a basic test case to see if it actually works. If so then I will upload my bastardized DalvikVMAdditionsForSmack.jar along with the source code in case anyone in the future wants to try and get Smack working on Android.

The latest roadblock appears to be that Android doesn’t ship with a security provider for SaslClientFactory.DIGEST-MD5. If I disable SASL and try to connect to jabber.org:5222 I get disconnected with a 503 error. From the looks of it, this is because jabber.org requires SASL… but I could be wrong and using the Smack library incorrectly. Either way, I am able to connect to and exchange XML with jabber.org on Android 1.6 using Smack but given the new issue I am still roadblocked from actually doing anything with it. I am going to take a little break from Smack and explore some other options tomorrow, but I will try to upload my changes before that so if someone else wants to pick it up they can.

Hi,

I’ve done exactly the requested patching on smack/trunk.

SASL is implementet with apache/harmony class definitions and 2 implementations for Digest-MD5 and PLAIN.

BeanInfo was replaced with reflection.

DNSUtil was replaced with a xbill based implementation.

Everything is apache licenced, download at http://github.com/rtreffer/asmack

Login as rtreffer@googlemail.com worked, so DNS/SRV, introspection and SASL work. MD5-Digest was tested against another jabber server and worked like a charm.

PS: Did I mention the AndroidDebugger to dump all stanzas to logcat?

Never mind. Adding @gmail.com to the user name seemed to do the trick.

And thanks to treffer, nice work.