Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Android IL2CPP Error.

Discussion in 'Android' started by wiyi, Feb 25, 2016.

  1. wiyi

    wiyi

    Joined:
    Feb 20, 2013
    Posts:
    17
    [To marshal a manged method,please add an attribute named "MonoPInvokeCallback' to the method definition.]

    -----------------------------------------------------------------------------------------
    When I add this
    [MonoPInvokeCallback(typeof(GotyeCallback))]
    static void Test(int event_code, IntPtr args){}

    build error:
    [Assets/TEST1.cs(1018,18): error CS0246: The type or namespace name `MonoPInvokeCallback' could not be found. Are you missing a using directive or an assembly reference?]
     
  2. wiyi

    wiyi

    Joined:
    Feb 20, 2013
    Posts:
    17
    unity3d 5.3.2f1
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @wiyi

    Unfortunately the whole MonoPInvokeCallback thing is a bit of a hack to make calls like this work with an AOT compiler. You can poke around on Google for the long and sordid story if you would like to. :)

    The short answer is that you need to implement the MonoPInvokeCallbackAttribute in your code somewhere. You can use this implementation:

    Code (CSharp):
    1. public class MonoPInvokeCallbackAttribute : System.Attribute
    2. {
    3.      private Type type;
    4.      public MonoPInvokeCallbackAttribute( Type t ) { type = t; }
    5. }
    Some more details are available here: http://answers.unity3d.com/questions/191234/unity-ios-function-pointers.html