Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[linker] preserve interfaces on Java types
Fixes: #7097 Context: xamarin/monodroid@a619cbe Usage of a `Google.Android.Material.TextField.TextInputEditText`: var filterBox = FindViewById<TextInputEditText>(Resource.Id.filterBox); filterBox.TextChanged += (s, e) => { }; Crashes at runtime with: android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not load type '{0}' from assembly '{1}'., Android.Text.ITextWatcherInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null at System.RuntimeTypeHandle.GetTypeByName(String , Boolean , Boolean , StackCrawlMark& , Boolean ) at System.RuntimeType.GetType(String , Boolean , Boolean , StackCrawlMark& ) at System.Type.GetType(String , Boolean ) at Android.Runtime.AndroidTypeManager.RegisterNativeMembers(JniType , Type , ReadOnlySpan`1 ) --- End of stack trace from previous location --- at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* ) at Android.Runtime.JNIEnv.FindClass(String ) at Android.Runtime.JNIEnv.AllocObject(String ) at Android.Runtime.JNIEnv.StartCreateInstance(String , String , JValue* ) at Android.Runtime.JNIEnv.StartCreateInstance(String , String , JValue[] ) at Android.Text.TextWatcherImplementor..ctor(Object , EventHandler`1 , EventHandler`1 , EventHandler`1 ) at Android.Widget.TextView.add_TextChanged(EventHandler`1 ) at AndroidApp1.MainActivity.OnCreate(Bundle savedInstanceState) at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr , IntPtr , IntPtr ) at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V , IntPtr , IntPtr , IntPtr ) at crc64a6e0c00971f6cd91.MainActivity.n_onCreate(Native Method) at crc64a6e0c00971f6cd91.MainActivity.onCreate(MainActivity.java:29) The problem being that the linker completely removed the `ITextWatcher` interface, and the `Android.Text.TextWatcherImplementor` type no longer implemented that interface. It appears we should preserve interfaces in .NET 6 for Java types *except* if the type defines: [Android.Runtime.Register (DoNotGenerateAcw = true)] This is on types like `Android.App.Activity` where we would *not* need to preserve all the interfaces. However, types like `TextWatcherImplementor` would get their interfaces preserved appropriately.
- Loading branch information