Android IL2CPP Error

[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?]

unity3d 5.3.2f1

@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. :slight_smile:

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

public class MonoPInvokeCallbackAttribute : System.Attribute
{
     private Type type;
     public MonoPInvokeCallbackAttribute( Type t ) { type = t; }
}

Some more details are available here: http://answers.unity3d.com/questions/191234/unity-ios-function-pointers.html