[Android] NoClassDefFoundError: java.net.IDN

I’m running Smack 4.1.3 on Android 2.2 and get this error:

java.lang.NoClassDefFoundError: java.net.IDN
     at de.measite.minidns.util.NameUtil.toByteArray(NameUtil.java:56)
     at de.measite.minidns.Question.toByteArray(Question.java:123)
     at de.measite.minidns.Question.hashCode(Question.java:138)
     at java.util.LinkedHashMap.get(LinkedHashMap.java:247)
     at org.jxmpp.util.cache.LruCache.get(LruCache.java:90)
     at org.jxmpp.util.cache.ExpirationCache.get(ExpirationCache.java:57)
     at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver$1.get(MiniDnsResolver.java:54)
     at de.measite.minidns.Client.query(Client.java:229)
     at de.measite.minidns.Client.query(Client.java:149)
     at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.lookupSRVRecords(MiniDnsResolver.java:79)
     at org.jivesoftware.smack.util.DNSUtil.resolveDomain(DNSUtil.java:171)
     at org.jivesoftware.smack.util.DNSUtil.resolveXMPPDomain(DNSUtil.java:120)
     at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMPPConnection.java:574)
     at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:552)
     at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:830)
     at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:365)
     at org.kontalk.service.XMPPConnectionHelper.connectOnce(XMPPConnectionHelper.java:192)
     at org.kontalk.service.XMPPConnectionHelper.connectOnce(XMPPConnectionHelper.java:141)
     at org.kontalk.client.NumberValidator.initConnection(NumberValidator.java:478)
     at org.kontalk.client.NumberValidator.run(NumberValidator.java:201)
     at org.kontalk.client.NumberValidator.run(NumberValidator.java:210)
     at java.lang.Thread.run(Thread.java:1096)

Since java.net.IDN is available since API level 9 (http://developer.android.com/reference/java/net/IDN.html) Smack will not work on Android 2.2. Is there anything I can do besides modifying Smack code?

You don’t need to modify Smack, simply set a resolver similar to MiniDnsResolver but without a cache.

Thanks Flow. I can see the default resolver for Android is indeed MiniDNS. I’m including the dnsjava resolver just for the flavour with minSDK set to 8, however I also have minidns compiled in. How can I prevent it from loading and taking precedence over the dnsjava resolver? Can I even exclude it from the build altogether?

Maybe with something like this? Am I correct?

SmackConfiguration.addDisabledSmackClass("org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver");

I don’t recommend using dnsjava. My suggestion was to simply create a MiniDnsResolver that is exactly the same code as the one shipped by Smack, but without the cache (which triggers the path where java.net.IDN is invoked), and to set that resolver with DNSUtil.setDNSResolver(myJava8MiniDnsResolver).

Ok thanks, I’ll arrange that.

By the way, any issue in particular why you don’t recommend using dnsjava?