Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Unity’s Demo Team is excited to share their upcoming interactive demo, Book of the Dead. See more information here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

UnitySendMessage Unsatisfied Link Error Native Method Not Found

Discussion in 'Android' started by Kennethljj, Jan 3, 2014.

  1. Kennethljj

    Kennethljj

    Joined:
    Feb 13, 2013
    Posts:
    17
    Hi All,

    I am integrating a plugin into my project whereby I created a method to send the result from the java plugin to Unity C#.
    I created an empty project to test and UnitySendMessage works fine, able to find the object and the method is found.

    However, when I integrate it into my main project, I get a UnsatisfiedLinkError: Native Method Not Found.
    May I know if there are any limitations that will prevent UnitySendMessage from working correctly?
    Currently using Unity 3.5.7 and using NGUI too.

    Here is part of my java class plugin whereby another event upon completion will call the reportResult method.
    Code (csharp):
    1.  
    2. public class blah extends UnityPlayerActivity{
    3.  
    4.         @Override
    5.     public void onCreate (Bundle savedInstanceState){
    6.         super.onCreate(savedInstanceState);
    7.     }
    8.  
    9.         public static void reportResult (String str)
    10.     {
    11.         UnityPlayer.UnitySendMessage("GameObject", "UnityMethod", str);
    12.     }
    13. }
    14.  
    My Receiver in Unity in a gameobject called "GameObject"
    Code (csharp):
    1.  
    2. AndroidJavaClass jc = null;
    3.  
    4. void UnityMethod(string str)
    5. {
    6.     Debug.Log ("SUCCESS: " + str);
    7. }
    8.  
    9. void Start()
    10. {
    11.     DontDestroyOnLoad (gameObject);
    12.     jc = new AndroidJavaClass (javaActivity);
    13. }
    14.  
    15. //Some other method calls...
    16.  
     
  2. Agent_007

    Agent_007

    Joined:
    Dec 18, 2011
    Posts:
    899
    Have you imported the Unity classes.jar file to Java project?
     
  3. Kennethljj

    Kennethljj

    Joined:
    Feb 13, 2013
    Posts:
    17
    Yes. I have imported the classes.jar to the java project and added it as a dependency. I have tried using the same jar file on my test project as well as my main project. However, it only works on my test project and I could not figure out why.
     
  4. Kennethljj

    Kennethljj

    Joined:
    Feb 13, 2013
    Posts:
    17
    Have anybody met this problem? Would be great if someone could advise me on what to look out for.
    Thanks in advance.
     
  5. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    524
    It sounds like your main project doesn't correctly load the Unity native libraries. What does your logcat say except "UnsatisfiedLinkError: Native Method Not Found."?
     
  6. Kennethljj

    Kennethljj

    Joined:
    Feb 13, 2013
    Posts:
    17
    Hi @bitter. Thanks for the reply.

    After I saw your comment, I tried to refresh and rebuild the project to get the logcat.
    However, it seems that the problem has been resolved by itself!?
    I did the same thing on multiple occasions however the problem was there. (Did not make any changes today)
    My guess was that during compile time, Unity might have problems reading the native libraries or the plugin jar files that causes the error to take place.

    Will post again if I encounter the problem, together with the logcat. Thanks a lot.
     
  7. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    466
    One way that you can run into this problem is, if you have any logic that is triggered *very* early, such as in response to override onCreate() of your own custom Application class, and that results in calling UnitySendMessage, you might be trying to call Unity *before* Unity has actually loaded its native libraries. This will result in this crash. So you have to make sure to defer such calls until later (such as in response to the C# calling you and telling you that it's ready, or other such schemes).
     
    rsavin likes this.