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

Exception : No such proxy method: AndroidUtilitiesPlugin+a.onButtonTapped(System.Int32)

Discussion in 'Editor & General Support' started by DidzTM, Nov 21, 2019.

  1. DidzTM

    DidzTM

    Joined:
    Jan 30, 2018
    Posts:
    17
    Hi,
    I'm facing this problem with my android plugin since a udpate to the last version of unity.

    Java code
    Code (CSharp):
    1.  
    2. public class AndroidBox  {
    3.    private static final AndroidBox ourInstance = new AndroidBox();
    4.    public static Activity mainActivity;
    5.    private static final String LOGTAG = "AndroidBox";
    6.  
    7.    public static AndroidBox getInstance()
    8.   {
    9.      return ourInstance;
    10.   }
    11.  
    12.    public interface AlertViewCallback {
    13.         public void onButtonTapped(int id);
    14.         public void testCallback(String test);
    15.    }
    16.    public void testCallback(AlertViewCallback callback){
    17.         callback.testCallback(("test callback"));
    18.    }
    19.    public void showAlertView(String[] strings,final  AlertViewCallback callback)
    20.    {
    21.         if (strings.length<3)
    22.         {
    23.             Log.i(LOGTAG,"Error - expected at least 3 strings, got " + strings.length);
    24.             return;
    25.         }
    26.         DialogInterface.OnClickListener myClickListener = new DialogInterface.OnClickListener() {
    27.         @Override
    28.          public void onClick(DialogInterface dialogInterface, int id) {
    29.                 Log.i(LOGTAG, "Tapped: " + id);
    30.                 callback.onButtonTapped(id);
    31.                 dialogInterface.dismiss();
    32.           }
    33.         };
    34.  
    35.         AlertDialog alertDialog = new AlertDialog.Builder(mainActivity)
    36.                 .setTitle(strings[0])
    37.                 .setMessage(strings[1])
    38.                 .setCancelable(false)
    39.                 .create();
    40.         alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL,strings[2],myClickListener);
    41.         if (strings.length>3)
    42.             alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE,strings[3],myClickListener);
    43.         if (strings.length>4)
    44.             alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,strings[4],myClickListener);
    45.         alertDialog.show();
    46.   }
    47. }
    c# code
    Code (CSharp):
    1. public class AndroidUtilitiesPlugin : MonoBehaviour
    2. {
    3.     private AndroidJavaClass _pluginAndroidBoxClass;
    4.     private AndroidJavaObject _pluginAndroidBoxInstance;
    5.     private void Start()
    6.     {
    7.         ShowAlertDialog(new string[] { "test","test","ok"});  
    8.     }
    9.     public AndroidJavaClass PluginAndroidBoxClass
    10.     {
    11.         get
    12.         {
    13.             if (_pluginAndroidBoxClass == null)
    14.             {
    15.                 _pluginAndroidBoxClass = new AndroidJavaClass(pluginAndroidPath + ".AndroidBox");
    16.                 _pluginAndroidBoxClass.SetStatic<AndroidJavaObject>("mainActivity", activity);
    17.             }
    18.             return _pluginAndroidBoxClass;
    19.         }
    20.     public AndroidJavaObject PluginAndroidBoxInstance
    21.     {
    22.         get
    23.         {
    24.             if (_pluginAndroidBoxInstance == null)
    25.             {
    26.                 _pluginAndroidBoxInstance = PluginAndroidBoxClass.CallStatic<AndroidJavaObject("getInstance");
    27.             }
    28.             return _pluginAndroidBoxInstance;
    29.         }
    30.     }
    31.     public AndroidJavaClass PluginAndroidBoxClass
    32.     {
    33.         get
    34.         {
    35.             if (_pluginAndroidBoxClass == null)
    36.             {
    37.                 _pluginAndroidBoxClass = new AndroidJavaClass(pluginAndroidPath + ".AndroidBox");
    38.                 _pluginAndroidBoxClass.SetStatic<AndroidJavaObject>("mainActivity", activity);
    39.             }
    40.             return _pluginAndroidBoxClass;
    41.         }
    42.     }
    43.  class AlertViewCallback : AndroidJavaProxy
    44.     {
    45.         private System.Action<int> alertHandler;
    46.         public AlertViewCallback(System.Action<int> alertHandlerIn) : base(pluginAndroidPath + ".AndroidBox$AlertViewCallback")
    47.         {
    48.             alertHandler = alertHandlerIn;
    49.         }
    50.         public void onButtonTapped(int index)
    51.         {
    52.             Debug.Log("Button tapped: " + index);
    53.             if (alertHandler != null) alertHandler(index);
    54.         }
    55.         public void testCallback(string test)
    56.         {
    57.             Debug.Log(test);
    58.         }
    59.     }
    60.     public void ShowAlertDialog(string[] strings, System.Action<int> handler = null)
    61.     {
    62.         if (strings.Length < 3)
    63.         {
    64.             Debug.LogError("AlertView requires at least 3 strings");
    65.             return;
    66.         }
    67.  
    68.         if (Application.platform == RuntimePlatform.Android)
    69.             PluginAndroidBoxInstance.Call("showAlertView", new object[] { strings, new AlertViewCallback(handler) });
    70.         else
    71.             Debug.LogWarning("AlertView not supported on this platform");
    72.     }
    73. }


    When calling the ShowAlertDialog the alert dialog is working fine but now when I click on one button a have the error :
    Create Thread: Exception : No such proxy method: AndroidUtilitiesPlugin+a.onButtonTapped(System.Int32)

    So it's on the callback of onButtonTapped, but why? Before, I never had that error.
     
    Last edited: Nov 21, 2019
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,653
    Are you using mono or il2cpp?
    On il2cpp you may need to explicitly mark your class so that methods don't get stripped.
     
  3. DidzTM

    DidzTM

    Joined:
    Jan 30, 2018
    Posts:
    17
    Ok thank you for your fast response, I'm using il2cpp but do you have an example for me ?


    And in the "a.onButtonTapped" what is the "a" ?

    And the problem is only with the alerDialog in that part of the code:

    1. public void onClick(DialogInterface dialogInterface, int id) {
    2. Log.i(LOGTAG, "Tapped: " + id);
    3. callback.onButtonTapped(id); <----------------
    4. dialogInterface.dismiss();
    5. }
     
    Last edited: Nov 21, 2019
  4. DidzTM

    DidzTM

    Joined:
    Jan 30, 2018
    Posts:
    17
    Ok I find why... I use a plugin (Obfuscator) to obfuscate the code... :mad:
    Thank you for your time !:D