Commit 0b7f93b
[jnimarshalmethod-gen] Do not miss registered methods (#357)
Fixes: #356
`Extensions.CheckMethod()` implicitly required that assemblies being
processed contained debug symbols, because it used
`ParameterDefinition.Name` in order to associate the `name` parameter
of the `[Register]` custom attribute with the Java-side name.
(`ParameterDefinition.Name` was via
`registerAttribute.Constructor.Parameters`.)
The problem is that if an assembly *doesn't* contain debug symbols,
then `ParameterDefinition.Name` may be empty, meaning we may
*skip over* methods with `[Register]` attributes.
This in turn means that those methods won't be registered, which can
result in a runtime crash. For example:
I/mono-stdout( 2532): Registering JNI marshal methods in Xamarin.Forms.Platform.Android.CellAdapter
W/art ( 2532): Attempt to remove index outside index area (6 vs 7-7)
W/art ( 2532): JNI WARNING: DeleteLocalRef(0x1bf00019) failed to find entry
The "traditional" Xamarin.Android Java Callable Wrapper describes 10
methods to register for this type:
__md_methods =
"n_onItemLongClick:(Landroid/widget/AdapterView;Landroid/view/View;IJ)Z:GetOnItemLongClick_Landroid_widget_AdapterView_Landroid_view_View_IJHandler:Android.Widget.AdapterView/IOnItemLongClickListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\n" +
"n_onActionItemClicked:(Landroid/view/ActionMode;Landroid/view/MenuItem;)Z:GetOnActionItemClicked_Landroid_view_ActionMode_Landroid_view_MenuItem_Handler:Android.Views.ActionMode/ICallbackInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\n" +
"n_onCreateActionMode:(Landroid/view/ActionMode;Landroid/view/Menu;)Z:GetOnCreateActionMode_Landroid_view_ActionMode_Landroid_view_Menu_Handler:Android.Views.ActionMode/ICallbackInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\n" +
"n_onDestroyActionMode:(Landroid/view/ActionMode;)V:GetOnDestroyActionMode_Landroid_view_ActionMode_Handler:Android.Views.ActionMode/ICallbackInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\n" +
"n_onPrepareActionMode:(Landroid/view/ActionMode;Landroid/view/Menu;)Z:GetOnPrepareActionMode_Landroid_view_ActionMode_Landroid_view_Menu_Handler:Android.Views.ActionMode/ICallbackInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\n" +
"n_onItemClick:(Landroid/widget/AdapterView;Landroid/view/View;IJ)V:GetOnItemClick_Landroid_widget_AdapterView_Landroid_view_View_IJHandler:Android.Widget.AdapterView/IOnItemClickListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\n" +
"n_onActionItemClicked:(Landroid/support/v7/view/ActionMode;Landroid/view/MenuItem;)Z:GetOnActionItemClicked_Landroid_support_v7_view_ActionMode_Landroid_view_MenuItem_Handler:Android.Support.V7.View.ActionMode/ICallbackInvoker, Xamarin.Android.Support.v7.AppCompat\n" +
"n_onCreateActionMode:(Landroid/support/v7/view/ActionMode;Landroid/view/Menu;)Z:GetOnCreateActionMode_Landroid_support_v7_view_ActionMode_Landroid_view_Menu_Handler:Android.Support.V7.View.ActionMode/ICallbackInvoker, Xamarin.Android.Support.v7.AppCompat\n" +
"n_onDestroyActionMode:(Landroid/support/v7/view/ActionMode;)V:GetOnDestroyActionMode_Landroid_support_v7_view_ActionMode_Handler:Android.Support.V7.View.ActionMode/ICallbackInvoker, Xamarin.Android.Support.v7.AppCompat\n" +
"n_onPrepareActionMode:(Landroid/support/v7/view/ActionMode;Landroid/view/Menu;)Z:GetOnPrepareActionMode_Landroid_support_v7_view_ActionMode_Landroid_view_Menu_Handler:Android.Support.V7.View.ActionMode/ICallbackInvoker, Xamarin.Android.Support.v7.AppCompat\n" +
"";
Meanwhile, `jnimarshalmethod-gen.exe` only finds and generates *6*:
[JniAddNativeMethodRegistration]
public static void __RegisterNativeMembers (JniNativeMethodRegistrationArguments args)
{
Console.WriteLine ("Registering JNI marshal methods in Xamarin.Forms.Platform.Android.CellAdapter");
args.AddRegistrations (new JniNativeMethodRegistration[6] {
new JniNativeMethodRegistration ("n_onActionItemClicked", "(Landroid/view/ActionMode;Landroid/view/MenuItem;)Z", new Func<IntPtr, IntPtr, IntPtr, IntPtr, bool> (__<$>_jni_marshal_methods.n_onActionItemClicked_Landroid_view_ActionMode_Landroid_view_MenuItem_)),
new JniNativeMethodRegistration ("n_onCreateActionMode", "(Landroid/view/ActionMode;Landroid/view/Menu;)Z", new Func<IntPtr, IntPtr, IntPtr, IntPtr, bool> (__<$>_jni_marshal_methods.n_onCreateActionMode_Landroid_view_ActionMode_Landroid_view_Menu_)),
new JniNativeMethodRegistration ("n_onDestroyActionMode", "(Landroid/view/ActionMode;)V", new Action<IntPtr, IntPtr, IntPtr> (__<$>_jni_marshal_methods.n_onDestroyActionMode_Landroid_view_ActionMode_)),
new JniNativeMethodRegistration ("n_onPrepareActionMode", "(Landroid/view/ActionMode;Landroid/view/Menu;)Z", new Func<IntPtr, IntPtr, IntPtr, IntPtr, bool> (__<$>_jni_marshal_methods.n_onPrepareActionMode_Landroid_view_ActionMode_Landroid_view_Menu_)),
new JniNativeMethodRegistration ("n_onItemClick", "(Landroid/widget/AdapterView;Landroid/view/View;IJ)V", new Action<IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr> (__<$>_jni_marshal_methods.n_onItemClick_Landroid_widget_AdapterView_Landroid_view_View_IJ)),
new JniNativeMethodRegistration ("n_onItemLongClick", "(Landroid/widget/AdapterView;Landroid/view/View;IJ)Z", new Func<IntPtr, IntPtr, IntPtr, IntPtr, float, float, bool> (__<$>_jni_marshal_methods.n_onItemLongClick_Landroid_widget_AdapterView_Landroid_view_View_IJ))
});
}
It's this mismatch which causes the runtime crash, and fixing
`Extensions.CheckMethod()` to not require debug symbols allows all
the methods to be found.1 parent f4c953f commit 0b7f93b
1 file changed
+12
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
254 | 257 | | |
255 | 258 | | |
256 | 259 | | |
| |||
491 | 494 | | |
492 | 495 | | |
493 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
494 | 506 | | |
495 | 507 | | |
496 | 508 | | |
| |||
0 commit comments