- Home /
android plugin app crashing
Hi,
I did follow official unity documentation to do eclipse based unity project. Then I read official docs how to call native java code using plugins. I created test project and was able to call from c# java method I created on my activity of android project which extends UnityPlayerActivity.
what I did was putting method on main activity and in c# called it this way
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
Debug.Log("what am I?:"+jo.Call<string>("toString"));
jo.Call("myMethod");
This resulted to printing activity name and calling my method on the main activity object as expected.
Now with my real porject I'm using Qcar qualcomm library and this changes a situation a little bit because my activity which extends UnityPlayerActivity is not the main one now. Qcar activity is and it must be main one for some reason otherwise it does not initialize itself properly. My app is working fine this way.
Problem is that now when I call
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
Debug.Log("what am I?:"+jo.Call<string>("toString"));
It does not give me my activity object but instead qcar one which I have no control over.
I still can access my activity class by
AndroidJavaClass jc = new AndroidJavaClass("com.mypack.myapp.myactivity");
but this is in static way, its not constructed activity object. I did create static method on it which constructs new plain object and returns it. This was working ok as well but calling any method on this new constructed plain object crashes application completely. With nothing meaningful in logs. just signal 11 (SIGSEGV), fault addr 00000000.
also tried to construct my own plain java object using this
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("com.mypack.myapp.myplainobject");
Debug.Log("what am I?:"+jo.Call<string>("toString"));
results in nothing being logged.
what is a proper way to create or call own object on native code and not getting segfault? Or is there a way how to get reference to my app activity other than currentActivity?
Thanks a lot. S.
Hi, I'm having a similar issue and I was wondering you found an anser for this yet?
Hi, yes I did but can;t remember exactly how cos I found more things which were wrong at the same time. actually I was creating class that was implmenting activity but was not registred as activity in manifet file. Then when it was in manifest It was created actueally on run time itself so creating it again was not good as well. Than I removed activity implementation fron the class and in methods I called I was tryint to run some stuff which required to be run on UI thread not on backround this was creating problems as well. I can't remember now at what stage I had this issue. Basically it was my lack of conceptual understanding of things. It was not easy to understand and put things right but that was my problem and now I have it working as needed.