0

My office has a network library for Android written in Java which enables fast and easy multiplayer networking,

Now, I've been assigned to make the library work on Unity3D, I did my homework on Unity Plugins, AndroidJavaClass, AndroidJavaProxy, AndroidJavaRunnable etc,

So, I can get most Android/Java methods work Like this,

From Java Class -

Class MyClass{
public static Helper helperInstance;

    Helper() {
        helperInstance = this;
    }

    public static Helper GetInstance() {

        if (helperInstance == null) {
            helperInstance = new Helper();
        }

        return helperInstance;
    }

    public Context mContext;

    public String Test(Context mContext) {
        this.mContext = mContext;
        Toast.makeText(mContext, "From Java With Love", Toast.LENGTH_SHORT).show();
        return "This Works";
    }
}

And can access the methods in the class or imported methods from C# like this -

AndroidJavaClass unityDefault = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject gameActivity = unityDefault.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject context = gameActivity.Call<AndroidJavaObject>("getApplicationContext");

        AndroidJavaClass hClass = new AndroidJavaClass("com.nixonok.pluginunity.Helper");
        AndroidJavaObject helperInstance = RightMeshClass.CallStatic<AndroidJavaObject>("GetInstance");

        helloText.text = helperInstance.Call<string>("Test", context);

The problem occurs when I implement the listener for network state change listener

            public interface StateListener {
                int SUCCESS = 1;
                int FAILURE = 2;
                int DISABLED = 3;
                int RESUME = 4;

                void StateChanged(int var1, int var2);
            }

            public Class MyClass implements StateListener{
        // Called By a Service on network event 
        @Override
            public void meshStateChanged(MeshID meshID, int i) {

            }
            Helper() {
                        helperInstance = this;
                    }

                    public static Helper GetInstance() {

                        if (helperInstance == null) {
                            helperInstance = new Helper();
                        }

                        return helperInstance;
                    }

                    public Context mContext;

                    public String Test(Context mContext) {
                        this.mContext = mContext;
                        Toast.makeText(mContext, "From Java With Love", Toast.LENGTH_SHORT).show();
                        return "Even This doesn't Work now";
                    }

                    void init(){
                        nService nn = new nService(mContext, this);
                        // Sending context of the listener impliment to service
                    }
            }

Now, The the plugin won't work at all, Not even the Test method,

I made an Interface callback in C# working using AndroidJavaProxy but without the implement, on the Java class, the service won't start :/

Any good idea for me to get this working without needing to change anything in the library?

Thanks in advance :)

nixonok
  • 1
  • 1
  • What do you mean by "The the plugin won't work at all"? Do you get any errors? On the side of unity or android ? You can use `adb logcat` command to read any error messages generated by android – Aj_ Apr 03 '18 at 10:25
  • The simple class MeshHelper works fine without any error but when i write class MeshHelper implements StateListener and import interface method - @Override public void stateChanged(MeshID meshID, int i) { } Now i get the error - AndroidJavaException: java.lang.ClassNotFoundException: com.w3e.nixonok.meshpluginunity.MeshHelper java.lang.ClassNotFoundException: com.w3e.nixonok.meshpluginunity.MeshHelper – nixonok Apr 18 '18 at 04:58

0 Answers0