1

I am making an android plugin for Unity, I need to integrate XMPP in Unity so first I am trying to create a connection of XMPP and send and receive a message. It's working fine in android, I am able to send and receive message But when I export .jar file and use in Unity so I got below error while I create connection

SmackInitialization: Could not determine Smack version
  java.lang.NullPointerException: lock == null
  at java.io.Reader.<init>(Reader.java:64)
  at java.io.InputStreamReader.<init>(InputStreamReader.java:122)
  at java.io.InputStreamReader.<init>(InputStreamReader.java:57)
  at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:61)
  at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
  at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
  at com.arvaan.myplugins.ToastExample.connectXMPP(ToastExample.java:99)
  at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
  at com.unity3d.player.UnityPlayer.a(Unknown Source)
  at com.unity3d.player.UnityPlayer$b$1.handleMessage(Unknown Source)
  at android.os.Handler.dispatchMessage(Handler.java:98)
  at android.os.Looper.loop(Looper.java:234)
  at com.unity3d.player.UnityPlayer$b.run(Unknown Source)

I don't know what is an issue with Smack, I am new in Unity, I know how to create plugins and call method in Unity but don't know what's wrong over here.

Please check code :

public class ToastExample extends UnityPlayerActivity implements ConnectionListener, ChatManagerListener, RosterListener, PingFailedListener, StanzaListener, MessageListener, ChatMessageListener {

private static final String TAG = ToastExample.class.getSimpleName();
private AbstractXMPPConnection mConnection = null;
private ChatManager chatManager;
private Chat chat;
private Context context;
private String userName = "";
private String passWord = "";
private String objectName = "";
private static ToastExample instance;

public ToastExample() {
    this.instance = this;
}
public static ToastExample instance() {
    if (instance == null) {
        instance = new ToastExample();
    }
    return instance;
}
public void setContext(Context context) { // This is also working fine
    Log.e(TAG, "setContext called");
    this.context = context;
}
public void showMessage(String message) { // I can able to see toast
    Toast.makeText(this.context, message, Toast.LENGTH_SHORT).show();
}

public void connectXMPP(String host, int port, String userName, String passWord) {
    Log.e(TAG, "_connectXMPP called");
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder(); // Here i got error
    configBuilder.setUsernameAndPassword(userName, passWord);
    ...............
    ...............
}

I am using below .Jar file in My Plugin and Unity

smack-core-4.1.4.jar
smack-extensions-4.1.4.jar
smack-im-4.1.4.jar
smack-android-4.1.4.jar
smack-android-extensions-4.1.4.jar
smack-tcp-4.1.4.jar
jxmpp-util-cache-0.4.2.jar
jxmpp-core-0.4.2.jar
jxmpp-jid-0.4.2.jar
jxmpp-stringprep-libidn-0.4.2.jar
minidns-core-0.2.0.jar**

Someone is also facing this issue but not found Check more

Please help me to sort out this issue, Thanks in Advance.!!!

1 Answer 1

1

Since nobody has answered here I how I solved it after 4 days R&D:

  1. Please exrect all classes of Smack-core-4.1.1.jar file and past inside your app.
  2. There is other 3 more file : version, smack-config.xml,jul.properties , Please paste this file in your Assests folder inside app.
  3. In Smack packages there is one class : SmackInitialization.java, please replace below code. Code Here
  4. Once you done please make .Jar file and use inside your Unity.Check Here

Let me know if you got same error i am happy to help you anytime for any solution.

Thanks

4
  • Hi, I tried your solution but I keep getting errors (with dns resolver). Can you please email me base project that you got working (with chat libs only)? I would really appreciate this. Thank you. Jun 11, 2017 at 19:28
  • gist.github.com/mmvlad/35f51f8c438651608350273437c1fc65 I added smack-resolver-minidns, minidns-core to libs but error still exists Jun 12, 2017 at 9:36
  • @VladyslavMelnychenko you can always post your own question if you want to get help. Link to this answer if you think it's related. Jan 6, 2018 at 23:14
  • You create an inputstream to read the hard coded strings bytes just to create a buffered reader to read the hardcoded line in the first place to set smackVersion. Nice! You could just delete the entire method and hardcode smackVersion = "4.1.4 (4.1.4 2015-09-14)"
    – Pierre
    Jul 5, 2019 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.