Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Maui-Blazor Project Template crashes in Release Mode #2246

Closed
aokocax opened this issue Aug 25, 2021 · 21 comments · Fixed by dotnet/android#6675
Closed

[Bug] Maui-Blazor Project Template crashes in Release Mode #2246

aokocax opened this issue Aug 25, 2021 · 21 comments · Fixed by dotnet/android#6675
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/android 🤖 t/bug Something isn't working

Comments

@aokocax
Copy link

aokocax commented Aug 25, 2021

Description

I'm trying to run the base maui-blazor template in Visual Studio 2022 Preview 3 in release mode. In android devices the application crashes as soon as the .net intro screen passes. (It works perfectly in debug mode)

Steps to Reproduce

  1. Create a new Maui-Blazor App
    image

  2. Run on release mode
    image

Expected Behavior

No crash.

Actual Behavior

The application crashes as soon as the .net intro screen passes.

Basic Information

  • Version with issue: .net 6 preview 7

  • Last known good version: -

  • IDE: Visual Studio 2022 Preview 3

  • Platform Target Frameworks: Android

    • Android: Android 9 (my phone arm64) , Android 7.1.2 (Nox virtual tablet x86)
    • UWP:
  • Android Support Library Version: 28

  • Nuget Packages:

  • Affected Devices:

Device Log

Time Device Name Type PID Tag Message
08-25 10:01:27.911 Samsung SM-G9550 Info 3402 art Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.companyname.MauiApp11-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.MauiApp11-1/lib/x86, /data/app/com.companyname.MauiApp11-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
at void crc6488302ad6e9e4df1a.MauiAppCompatActivity.n_onCreate(android.os.Bundle) (MauiAppCompatActivity.java:-2)
at void crc6488302ad6e9e4df1a.MauiAppCompatActivity.onCreate(android.os.Bundle) (MauiAppCompatActivity.java:46)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6692)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2621)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2729)
at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1480)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
at void android.os.Looper.loop() (Looper.java:154)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6198)
at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:891)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:781)

Time Device Name Type PID Tag Message
08-25 10:01:27.911 Samsung SM-G9550 Info 3402 art Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
at void crc6488302ad6e9e4df1a.MauiAppCompatActivity.n_onCreate(android.os.Bundle) (MauiAppCompatActivity.java:-2)
at void crc6488302ad6e9e4df1a.MauiAppCompatActivity.onCreate(android.os.Bundle) (MauiAppCompatActivity.java:46)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6692)
at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2621)
at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2729)
at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1480)
at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
at void android.os.Looper.loop() (Looper.java:154)
at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6198)
at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:891)
at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:781)

@Eilon
Copy link
Member

Eilon commented Aug 27, 2021

@aokocax does this also happen with a regular .NET MAUI app (no Blazor)?

@aokocax
Copy link
Author

aokocax commented Aug 27, 2021

Nope, it only crashes maui-blazor template. .Net Maui App works perfectly in release mode.

When I comment out this section in Maui-Blazor template
MainPage.xaml
<b:BlazorWebView HostPage="wwwroot/index.html">
<b:BlazorWebView.RootComponents>
<b:RootComponent Selector="app" ComponentType="{x:Type local:Main}" />
</b:BlazorWebView.RootComponents>
</b:BlazorWebView>

Maui-blazor app also works in release mode.

@Eilon
Copy link
Member

Eilon commented Aug 27, 2021

Thanks for the update, we will investigate.

@Eilon Eilon added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Aug 27, 2021
@aokocax
Copy link
Author

aokocax commented Aug 27, 2021

Thanks @Eilon ,
I am also investigating the issue.
If I can overcome this, I will be able to start submitting test applications to the android market. Unfortunately, signed APKs crash because of this.

@AWildTeddyBear
Copy link

I also just ran across this problem and was able to reproduce it. The workaround mentioned #2246 (comment) seems to run without crashing, however, I cannot navigate to any pages because of it.

@hartez
Copy link
Contributor

hartez commented Sep 7, 2021

It may be totally unrelated, but we have seen that exception on startup in Forms - see xamarin/Xamarin.Forms#8301 and xamarin/Xamarin.Forms#6703.

@Asyvix
Copy link

Asyvix commented Sep 23, 2021

@Eilon any updates in this issue? Could this be fixed in Preview9?

@aokocax
Copy link
Author

aokocax commented Sep 23, 2021

I also tried on mac but same problem persists. I think there is a problem on the android side, probably related to proguard.
Unfortunately, unlike xamarin forms, we cannot disable proguard in maui to test.

@aokocax
Copy link
Author

aokocax commented Oct 12, 2021

Unfortunately the problem still persists, not fixed in rc2 either.

@Asyvix
Copy link

Asyvix commented Oct 13, 2021

@Eilon @aokocax @hartez
I found a workaround. only need to add a few properties to your project settings.

<AndroidLinkMode>None</AndroidLinkMode>

and thats it!. now maui blazor app working.

@aokocax
Copy link
Author

aokocax commented Oct 13, 2021

Thank you very much @Asyvix
It worked as you said. Also I only added <AndroidLinkMode>None</AndroidLinkMode> and It works like a charm :)

@SteveSandersonMS
Copy link
Member

Reopening because the availability of a workaround isn't the quality bar we're going for :) This needs to be fixed.

@SilverioMiranda
Copy link

Same problem with MAUI preview 12, 21/01/2022

@jamesmontemagno
Copy link
Member

I think that the templates should probably include "Release" settings that override the defaults for architecture types, linker settings, and more. The UI for Xamarin.iOS/Android projects do this normally, but the templates ship with defaults. I think we just need to sync with those teams to configure the templates.

1.) @jonathanpeppers @Redth @dalexsoto thoughts as these apply to ios/android project templates as well
2.) We should add documentation for these settings @davidbritch thoughts?

@jonathanpeppers
Copy link
Member

If the workaround is <AndroidLinkMode>None</AndroidLinkMode>, then that isn't really a workaround. You can't really ship a Release build to an app store like that, the app size would be quite large.

I don't follow what would change in the templates here? We should figure out what the issue is?

The crash mentioned here: #4262

01-21 15:58:46.701  7867  7867 F crashpad: dlopen: dlopen failed: library "libandroidicu.so" not found: needed by /system/lib64/libharfbuzz_ng.so in namespace (default)
01-21 15:58:46.702  7783  7837 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4 in tid 7837 (ThreadPoolForeg), pid 7783 (nyname.mauiapp2)
01-21 15:58:46.770  7870  7870 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
01-21 15:58:46.771   284   284 I tombstoned: received crash request for pid 7837
01-21 15:58:46.772  7870  7870 I crash_dump64: performing dump of process 7783 (target tid = 7837)
01-21 15:58:46.777  7870  7870 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-21 15:58:46.777  7870  7870 F DEBUG   : Build fingerprint: 'google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys'
01-21 15:58:46.777  7870  7870 F DEBUG   : Revision: '0'
01-21 15:58:46.777  7870  7870 F DEBUG   : ABI: 'x86_64'
01-21 15:58:46.778  7870  7870 F DEBUG   : Timestamp: 2022-01-21 15:58:46+0000
01-21 15:58:46.778  7870  7870 F DEBUG   : pid: 7783, tid: 7837, name: ThreadPoolForeg  >>> com.companyname.mauiapp2 <<<
01-21 15:58:46.778  7870  7870 F DEBUG   : uid: 10155
01-21 15:58:46.778  7870  7870 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
01-21 15:58:46.778  7870  7870 F DEBUG   : Cause: null pointer dereference
01-21 15:58:46.778  7870  7870 F DEBUG   :     rax 000070fc876bf820  rbx 000070fc876bfdc0  rcx 0000000000000000  rdx 000070fc876bf820
01-21 15:58:46.778  7870  7870 F DEBUG   :     r8  fffffffffffffdd0  r9  000070fc876bfe40  r10 0000000000000000  r11 000070fc8c34bb30
01-21 15:58:46.779  7870  7870 F DEBUG   :     r12 000070fc876bfbe0  r13 000070fce442b550  r14 000070fe54b03098  r15 0000000000000000
01-21 15:58:46.779  7870  7870 F DEBUG   :     rdi 000070fc876bfdc0  rsi 0000000000000000
01-21 15:58:46.779  7870  7870 F DEBUG   :     rbp 0000000000000000  rsp 000070fc876bfba0  rip 000070fce49048fc
01-21 15:58:46.838  7870  7870 F DEBUG   : backtrace:
01-21 15:58:46.838  7870  7870 F DEBUG   :       #00 pc 000000000065d8fc  /apex/com.android.art/lib64/libart.so (void art::StackVisitor::WalkStack<(art::StackVisitor::CountTransitions)0>(bool)+156) (BuildId: 7fbaf2a1a3317bd634b00eb90e32291e)
01-21 15:58:46.838  7870  7870 F DEBUG   :       #01 pc 000000000069b25d  /apex/com.android.art/lib64/libart.so (art::Thread::GetCurrentMethod(unsigned int*, bool, bool) const+157) (BuildId: 7fbaf2a1a3317bd634b00eb90e32291e)
01-21 15:58:46.838  7870  7870 F DEBUG   :       #02 pc 0000000000430fed  /apex/com.android.art/lib64/libart.so (art::JNI<false>::FindClass(_JNIEnv*, char const*)+765) (BuildId: 7fbaf2a1a3317bd634b00eb90e32291e)
01-21 15:58:46.838  7870  7870 F DEBUG   :       #03 pc 0000000000047e5a  /data/app/~~0Qm6D1S0sO3f1lwfakN0PA==/com.companyname.mauiapp2-08UokVCH5k_PlbZEH_hhkA==/split_config.x86_64.apk!libmono-android.release.so (offset 0x11e000) (java_interop_jnienv_find_class+26) (BuildId: 3d04f8b946590175e97b89aee2e3b19ceed4b524)
01-21 15:58:46.838  7870  7870 F DEBUG   :       #04 pc 00000000000128ac  <anonymous:41640000>
01-21 15:58:47.095   284   284 E tombstoned: Tombstone written to: /data/tombstones/tombstone_03

I'll try to repro and see if we can find out the cause. It kind of looks like java_interop_jnienv_find_class tried to locate a class that was linked away?

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 26, 2022
…asses

Fixes: dotnet/maui#2246
Fixes: dotnet/maui#4262
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1447865

`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.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.

For now, let's preserve a few additional types that could fall into
the same issue:

    <type fullname="Android.Runtime.InputStreamAdapter" preserve="methods" />
    <type fullname="Android.Runtime.InputStreamInvoker" preserve="methods" />
    <type fullname="Android.Runtime.XmlResourceParserReader" preserve="methods" />
    <type fullname="Android.Runtime.XmlPullParserReader" preserve="methods" />
    <type fullname="Android.Runtime.XmlReaderResourceParser" preserve="methods" />
    <type fullname="Android.Runtime.XmlReaderPullParser" preserve="methods" />

This should hopefully fix issues like this, and hopefully not regress
app size that much.
@jonathanpeppers
Copy link
Member

We should hopefully have this fixed in the next MAUI preview.

The most precise workaround is to create a ILLink.Descriptors.xml file:

<linker>
    <assembly fullname="Mono.Android">
        <type fullname="Android.Runtime.InputStreamAdapter" preserve="methods" />
        <type fullname="Android.Runtime.InputStreamInvoker" preserve="methods" />
    </assembly>
</linker>

Put this in your .csproj as well:

<EmbeddedResource Include="ILLink.Descriptors.xml">
  <LogicalName>ILLink.Descriptors.xml</LogicalName>
</EmbeddedResource>

Details about the file format here.

@SilverioMiranda
Copy link

We should hopefully have this fixed in the next MAUI preview.

The most precise workaround is to create a ILLink.Descriptors.xml file:

<linker>
    <assembly fullname="Mono.Android">
        <type fullname="Android.Runtime.InputStreamAdapter" preserve="methods" />
        <type fullname="Android.Runtime.InputStreamInvoker" preserve="methods" />
    </assembly>
</linker>

Put this in your .csproj as well:

<EmbeddedResource Include="ILLink.Descriptors.xml">
  <LogicalName>ILLink.Descriptors.xml</LogicalName>
</EmbeddedResource>

Details about the file format here.

This fix wont work as expected.
Only works if you don't deployed any release version of maui before or with clean android emulator or app app with new ApplicationId

@jonathanpeppers
Copy link
Member

@SilverioMiranda did you try to Clean or Rebuild? What you’re describing sounds like an incremental build issue, when adding the new file.

@SilverioMiranda
Copy link

@jonathanpeppers yes, i did Clean Solution and Rebuild. Now after you tell about incremental build issue i deleted bin and obj folders and worked like a charm

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 27, 2022
…asses

Fixes: dotnet/maui#2246
Fixes: dotnet/maui#4262
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1447865

`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)
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 27, 2022
…asses

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 (dotnet#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)
jonathanpeppers added a commit to dotnet/android that referenced this issue Jan 28, 2022
…asses (#6675)

Fixes: dotnet/maui#2246
Fixes: dotnet/maui#4262
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1447865

Context: b7a368a

Revert "[One .NET] Do not preserve IO stream adapter/invoker (#5449)"

This reverts commit 051cad7.

If you run the `maui-blazor` template in a Release build:

	dotnet build -t:Run -c Release

it crashes at runtime:

	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, or *drop* `mono.android.jar` & `mono.android.dex` and treat
`Mono.Android.dll` as a "normal user assembly"…

This regresses `.apk` size by ~16KB:

	--"PackageSize": 2680724
	++"PackageSize": 2697108

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)
@aokocax
Copy link
Author

aokocax commented Jan 31, 2022

For MAUI-Blazor project, I tried all the mentioned methods (clean, rebuild) but the application started to crash again.

https://github.com/aokocax/MauiBlazorLinker

@SteveSandersonMS
Copy link
Member

@aokocax I think there's a mistake in your file https://github.com/aokocax/MauiBlazorLinker/blob/master/MauiBlazorLinker/ILLink.Descriptors.xml. Its contents don't look like what was suggested by @SilverioMiranda above.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 11, 2022
@mkArtakMSFT mkArtakMSFT added this to the 6.0.300-preview.14 milestone Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/android 🤖 t/bug Something isn't working
Projects
None yet