Smack (XMPP) version check problem only occurs on Unity

Hello,

I know that this may not be unity question, but I have no answer from smack community. So let me ask my question… there will be some users who used smack with unity.

I’m developing an Unity application (5.4.0f3) with Java/Andoid libraries as plugin. As server uses XMPP, I use smack to communicate with server. (Server is coded with prosody.im)

When I test codes without Unity, there is no problem. I can run application with smack via PC(win/java) or native Android app. But problem occurs when I run it with Unity.

I attached logcat below.
Do you have any idea? I googled this error but there were not many questions and no answers…

Thanks in advance

p.s. Error occurs at this line (Class#2.java:49)

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder();

especially in this method, code below occurs problem.

SmackConfiguration.getVersion();

– Error Log –

Could not determine Smack version java.lang.NullPointerException: lock == null at java.io.Reader.(Reader.java:64) at java.io.InputStreamReader.(InputStreamReader.java:122) at java.io.InputStreamReader.(InputStreamReader.java:57) at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:61 ) at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 ) at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration .java:38) at [remove package name for security issues].(Class#2.java:49) at [remove package name for security issues](Class#1.java:120) at [remove package name for security issues](Class#0.java:193) at [remove package name for security issues].MainActivity$3.run(MainActivity.java:70) at java.lang.Thread.run(Thread.java:818) FATAL EXCEPTION: Thread-22292 Process: com.aibrain.giar.lite, PID: 23634 java.lang.Error: FATAL EXCEPTION [Thread-22292] Unity version : 5.4.0f3 Device model : samsung SM-N920K Device fingerprint: [remove for security] Caused by: java.lang.ExceptionInInitializerError at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96 ) at org.jivesoftware.smack.ConnectionConfiguration.(ConnectionConfiguration .java:38) at [remove package name for security issues].(Class#2.java:49) at [remove package name for security issues](Class#1.java:120) at [remove package name for security issues](Class#0.java:193) at [remove package name for security issues].MainActivity$3.run(MainActivity.java:70) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.IllegalStateException: java.lang.IllegalArgumentException: is == null at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:11 9) ... 7 more Caused by: java.lang.IllegalArgumentException: is == null at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1634) at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:155) at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitializatio n.java:148) at org.jivesoftware.smack.SmackInitialization.(SmackInitialization.java:11 6) ... 7 more Force finishing activity com.aibrain.giar.lite/.MainActivity

Hi, there is in my github Working Library of XMPP implementation.

After all, I made intermediate server for XMPP connection…

Actually I don’t like this way, because I run two servers.

@naXa did you succeed to fix?

The problem is that all plain text resources from jar file are not included in dex file during conversion. And Smack (former ASmack) library crashes because it can’t access version file. I am not going to argue with Smack developers whether it’s a good idea to halt if you can’t read some resources file…
In rough words my solution is to repack APK file and include this missing version file and other potentially useful resources from jar. After repacking you need to sign APK file again.

List of resources:

  • org.jivesoftware.smack library:
    • jul.properties
    • smack-config.xml
    • version
  • org.jivesoftware.smack.im
    • smackim.xml
    • smackim.providers
  • org.jivesoftware.smack.tcp
    • smacktcp.providers
  • XPP3_1.1.4c_VERSION

Also I would like to share my shell script (Linux) for repacking APK file.

Script source code

#!/bin/sh

echo "[INFO] Removing signature"
zip -d "$1" "META-INF/*"
echo "[INFO] Adding resources"
aapt add -v "$1" META-INF/services/* org.jivesoftware.smack/* org.jivesoftware.smack.im/* org.jivesoftware.smack.tcp/* XPP3_1.1.4c_VERSION
echo "[INFO] Psst! Want to know a secret password? Try 'android' ;)"
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.android/debug.keystore "$1" androiddebugkey
echo "[INFO] Repacking is done!"

Usage

sh ./repack.sh ./project.apk

Requirements:

  1. zip, aapt, jarsigner tools should be available from terminal.
  2. ~/.android/debug.keystore file should be present. It’s a default debug keystore that is generated when you perform the first build in Eclipse / Android Studio. (more details)

By default this script uses debug key for signing your application. You can use your own key, just modify jarsigner line.

@ArinCherryBlossom, @solinv, @connatty, you may be interested in this answer.

I got solution please check this my answer in Stack Overflow: Check here