Skip to content

Commit 208b5fb

Browse files
[Microsoft.Android.Sdk.IlLink] preserve methods in Android.Runtime classes
Fixes: dotnet/maui#2246 Fixes: dotnet/maui#4262 Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1447865 Revert "[One .NET] Do not preserve IO stream adapter/invoker (#5449)" This reverts commit 051cad7. `dotnet new maui-blazor` crashes in Release mode with: Android.Runtime.JavaProxyThrowable: Exception_WasThrown, Android.Runtime.JavaProxyThrowable --- End of managed Android.Runtime.JavaProxyThrowable stack trace --- android.runtime.JavaProxyThrowable: System.ArgumentException: Arg_DlgtTargMeth at System.Delegate.CreateDelegate(Type , Type , String , Boolean , Boolean ) at System.Delegate.CreateDelegate(Type , Type , String ) at Android.Runtime.AndroidTypeManager.RegisterNativeMembers(JniType , Type , String ) --- End of stack trace from previous location --- at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* ) at Android.Runtime.JNIEnv.CallStaticObjectMethod(IntPtr , IntPtr , JValue* ) at Android.Runtime.JNIEnv.CallStaticObjectMethod(IntPtr , IntPtr , JValue[] ) 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.Runtime.InputStreamAdapter..ctor(Stream ) at Android.Runtime.InputStreamAdapter.ToLocalJniHandle(Stream ) at Android.Webkit.WebResourceResponse..ctor(String , String , Int32 , String , IDictionary`2 , Stream ) at Microsoft.AspNetCore.Components.WebView.Maui.WebKitWebViewClient.ShouldInterceptRequest(WebView view, IWebResourceRequest request) at Android.Webkit.WebViewClient.n_ShouldInterceptRequest_Landroid_webkit_WebView_Landroid_webkit_WebResourceRequest_(IntPtr , IntPtr , IntPtr , IntPtr ) at crc64d693e2d9159537db.WebKitWebViewClient.n_shouldInterceptRequest(Native Method) at crc64d693e2d9159537db.WebKitWebViewClient.shouldInterceptRequest(WebKitWebViewClient.java:39) at Rr.a(chromium-TrichromeWebViewGoogle.apk-stable-410410686:16) at org.chromium.android_webview.AwContentsBackgroundThreadClient.shouldInterceptRequestFromNative(chromium-TrichromeWebViewGoogle.apk-stable-410410686:2) --- End of managed Android.Runtime.JavaProxyThrowable stack trace --- android.runtime.JavaProxyThrowable: System.ArgumentException: Arg_DlgtTargMeth at System.Delegate.CreateDelegate(Type , Type , String , Boolean , Boolean ) at System.Delegate.CreateDelegate(Type , Type , String ) at Android.Runtime.AndroidTypeManager.RegisterNativeMembers(JniType , Type , String ) --- End of stack trace from previous location --- at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference , JniMethodInfo , JniArgumentValue* ) at Android.Runtime.JNIEnv.CallStaticObjectMethod(IntPtr , IntPtr , JValue* ) at Android.Runtime.JNIEnv.CallStaticObjectMethod(IntPtr , IntPtr , JValue[] ) 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.Runtime.InputStreamAdapter..ctor(Stream ) at Android.Runtime.InputStreamAdapter.ToLocalJniHandle(Stream ) at Android.Webkit.WebResourceResponse..ctor(String , String , Int32 , String , IDictionary`2 , Stream ) at Microsoft.AspNetCore.Components.WebView.Maui.WebKitWebViewClient.ShouldInterceptRequest(WebView view, IWebResourceRequest request) at Android.Webkit.WebViewClient.n_ShouldInterceptRequest_Landroid_webkit_WebView_Landroid_webkit_WebResourceRequest_(IntPtr , IntPtr , IntPtr , IntPtr ) at crc64d693e2d9159537db.WebKitWebViewClient.n_shouldInterceptRequest(Native Method) at crc64d693e2d9159537db.WebKitWebViewClient.shouldInterceptRequest(WebKitWebViewClient.java:39) at Rr.a(chromium-TrichromeWebViewGoogle.apk-stable-410410686:16) at org.chromium.android_webview.AwContentsBackgroundThreadClient.shouldInterceptRequestFromNative(chromium-TrichromeWebViewGoogle.apk-stable-410410686:2) It turns out that `Java.IO.InputStream.GetReadHandler()` was linked away. So we need to preserve: <linker> <assembly fullname="Mono.Android"> <type fullname="Android.Runtime.InputStreamAdapter" preserve="methods" /> <type fullname="Android.Runtime.InputStreamInvoker" preserve="methods" /> Long-term, we should consider reworking `mono.android.jar`, so that the linker *knows* about any C# methods called from Java from this library. This regresses apk size a reasonable amount: --"PackageSize": 2680724 ++"PackageSize": 2697108 Adding ~16kb. I considered adding: <type fullname="Android.Runtime.XmlResourceParserReader" /> <type fullname="Android.Runtime.XmlPullParserReader" /> <type fullname="Android.Runtime.XmlReaderResourceParser" /> <type fullname="Android.Runtime.XmlReaderPullParser" /> But this regressed app size by too much! 1,141,062 Package size difference 42.57% (of 2,680,724)
1 parent b7a368a commit 208b5fb

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Diff for: src/Microsoft.Android.Sdk.ILLink/PreserveLists/Mono.Android.xml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<assembly fullname="Mono.Android">
44
<type fullname="Android.Runtime.AnnotationAttribute" />
55
<type fullname="Android.Runtime.IJavaObject" />
6+
<type fullname="Android.Runtime.InputStreamAdapter" preserve="methods" />
7+
<type fullname="Android.Runtime.InputStreamInvoker" preserve="methods" />
68
<type fullname="Android.Runtime.JNIEnv">
79
<method name="Exit" />
810
<method name="Initialize" />
@@ -17,6 +19,8 @@
1719
<type fullname="Android.Runtime.LogLevel" />
1820
<type fullname="Android.Runtime.LogCategories" />
1921
<type fullname="Android.Runtime.NamespaceMappingAttribute" />
22+
<type fullname="Android.Runtime.OutputStreamAdapter" preserve="methods" />
23+
<type fullname="Android.Runtime.OutputStreamInvoker" preserve="methods" />
2024
<type fullname="Android.Runtime.PreserveAttribute" />
2125
<type fullname="Android.Runtime.RaiseThrowableEventArgs" />
2226
<type fullname="Android.Runtime.RegisterAttribute" />

Diff for: src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/BuildReleaseArm64SimpleDotNet.apkdesc

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
"Size": 3032
66
},
77
"assemblies/Java.Interop.dll": {
8-
"Size": 54720
8+
"Size": 55086
99
},
1010
"assemblies/Mono.Android.dll": {
11-
"Size": 78995
11+
"Size": 83182
1212
},
1313
"assemblies/rc.bin": {
1414
"Size": 1045
1515
},
1616
"assemblies/System.Linq.dll": {
17-
"Size": 10152
17+
"Size": 10157
1818
},
1919
"assemblies/System.Private.CoreLib.dll": {
20-
"Size": 508217
20+
"Size": 520945
2121
},
2222
"assemblies/System.Runtime.dll": {
23-
"Size": 2404
23+
"Size": 2410
2424
},
2525
"assemblies/UnnamedProject.dll": {
26-
"Size": 3545
26+
"Size": 3551
2727
},
2828
"classes.dex": {
2929
"Size": 345328
3030
},
3131
"lib/arm64-v8a/libmonodroid.so": {
32-
"Size": 382576
32+
"Size": 382680
3333
},
3434
"lib/arm64-v8a/libmonosgen-2.0.so": {
3535
"Size": 3176048
@@ -44,7 +44,7 @@
4444
"Size": 150024
4545
},
4646
"lib/arm64-v8a/libxamarin-app.so": {
47-
"Size": 12424
47+
"Size": 12384
4848
},
4949
"META-INF/BNDLTOOL.RSA": {
5050
"Size": 1213
@@ -80,5 +80,5 @@
8080
"Size": 1904
8181
}
8282
},
83-
"PackageSize": 2680724
83+
"PackageSize": 2697108
8484
}

0 commit comments

Comments
 (0)