xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] System.NotSupportedException: Unable to activate instance of type Project.Mobile.Droid.SplashScreenActivity from native handle 0xff957d6c (key_handle 0xefbe5c6). ---> System.MissingMethodException: No constructor found #11098

Closed EDMIStephen closed 4 years ago

EDMIStephen commented 4 years ago

Description

System.NotSupportedException. Seems similar to https://github.com/xamarin/Xamarin.Forms/issues/6550#issuecomment-625702458

Steps to Reproduce

  1. Build release build
    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'InternalRelease|AnyCPU'">
    <DebugSymbols>True</DebugSymbols>    <!-- true Enable debugger -->
    <DebugType>full</DebugType>    <!-- full enables debugger -->
    <Optimize>false</Optimize>    <!-- false enables the debugger -->
    <AssemblyName>AppName.Mobile.Droid.Internal</AssemblyName>
    <OutputPath>bin\InternalRelease\</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
    <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
    <Debugger>Xamarin</Debugger>
    <RunCodeAnalysis>false</RunCodeAnalysis>
    <AndroidSupportedAbis>armeabi-v7a</AndroidSupportedAbis>
    <AndroidEnableMultiDex>true</AndroidEnableMultiDex>
    <AotAssemblies>true</AotAssemblies>
    <EnableLLVM>true</EnableLLVM>
    <AndroidAotMode>Hybrid</AndroidAotMode>
    <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
    <AndroidDexTool>d8</AndroidDexTool>
    <AndroidLinkTool>r8</AndroidLinkTool>
    <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
    <AndroidLinkMode>SdkOnly</AndroidLinkMode>
    </PropertyGroup>
  2. App crashes on startup

Expected Behavior

App doesn't crash

Actual Behavior

App crashes on Startup

06-18 16:29:46.604 I/MonoDroid(31387): UNHANDLED EXCEPTION:
06-18 16:29:46.608 I/MonoDroid(31387): System.NotSupportedException: Unable to activate instance of type appName.Mobile.Droid.SplashScreenActivity from native handle 0xff957d6c (key_handle 0xefbe5c6). ---> System.MissingMethodException: No constructor found for appName.Mobile.Droid.SplashScreenActivity::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
06-18 16:29:46.608 I/MonoDroid(31387):    --- End of inner exception stack trace ---
06-18 16:29:46.608 I/MonoDroid(31387):   at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.608 I/MonoDroid(31387):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.608 I/MonoDroid(31387):    --- End of inner exception stack trace ---
06-18 16:29:46.609 I/MonoDroid(31387):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.609 I/MonoDroid(31387):   at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.609 I/MonoDroid(31387):   at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.609 I/MonoDroid(31387):   at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.609 I/MonoDroid(31387):   at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.609 I/MonoDroid(31387):   at Android.Content.ContextWrapper.n_AttachBaseContext_Landroid_content_Context_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native__base) [0x00000] in <e614fdc5579e440e9326c8e09ff62c60>:0 
06-18 16:29:46.609 I/MonoDroid(31387):   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.23(intptr,intptr,intptr)
06-18 16:29:46.621 W/rm.Mobile.Droi(31387): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
06-18 16:29:46.625 D/Mono    (31387): DllImport searching in: '__Internal' ('(null)').
06-18 16:29:46.625 D/Mono    (31387): Searching for 'java_interop_jnienv_throw'.
06-18 16:29:46.625 D/Mono    (31387): Probing 'java_interop_jnienv_throw'.
06-18 16:29:46.625 D/Mono    (31387): Found as 'java_interop_jnienv_throw'.
**System.NotSupportedException:** 'Unable to activate instance of type appName.Mobile.Droid.SplashScreenActivity from native handle 0xff957d6c (key_handle 0xefbe5c6).'

06-18 16:29:48.273 E/mono    (31387): 
06-18 16:29:48.273 E/mono    (31387): Unhandled Exception:
06-18 16:29:48.273 E/mono    (31387): System.NotSupportedException: Unable to activate instance of type appName.Mobile.Droid.SplashScreenActivity from native handle 0xff957d6c (key_handle 0xefbe5c6). ---> System.MissingMethodException: No constructor found for appName.Mobile.Droid.SplashScreenActivity::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
06-18 16:29:48.273 E/mono    (31387):    --- End of inner exception stack trace ---

Basic Information

Droid

    <PackageReference Include="Autofac.Extras.MvvmCross" Version="5.1.0" />
    <PackageReference Include="Fody"" Version="6.1.1" />
    <PackageReference Include="Nito.Collections.Deque" Version="1.0.4" />
    <PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />
    <PackageReference Include="FodyHelpers" Version="6.1.1" />
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="3.2.1" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.2.1" />
    <PackageReference Include="MvvmCross.Forms" Version="6.4.2" />
    <PackageReference Include="MvvmCross.Plugin.Json" Version="6.4.2" />
    <PackageReference Include="Realm" Version="4.3.0" />
    <PackageReference Include="Realm.Fody"" Version="4.3.0" />
    <PackageReference Include="Serilog.Sinks.Xamarin" Version="0.2.0.64" />
    <!-- https://github.com/xamarin/xamarin-android/issues/4731 for System.Runtime.Loader fix with AOT compilation -->
    <PackageReference Include="System.Runtime.Loader" Version="4.3.0">
      <ExcludeAssets>all</ExcludeAssets>
    </PackageReference>
    <PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
    <PackageReference Include="System.ValueTuple" Version="4.5.0" />
    <PackageReference Include="Xamarin.Android.Support.Compat" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.AndroidX.AppCompat.Resources" Version="1.1.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.2.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.3.4.3" />
    <PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.1.0.1" />
    <PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.1" />
    <PackageReference Include="Xamarin.Android.Arch.Core.Common" Version="1.1.1.3" />
    <PackageReference Include="Xamarin.Android.Arch.Lifecycle.Common" Version="1.1.1.3" />
    <PackageReference Include="Xamarin.Android.Arch.Lifecycle.Runtime" Version="1.1.1.3" />
    <PackageReference Include="Xamarin.Build.Download" Version="0.10.0" />
    <PackageReference Include="Xamarin.Firebase.Common" Version="71.1610.1" />
    <PackageReference Include="Xamarin.Firebase.Iid" Version="71.1710.1" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="71.1740.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="71.1620.2" />
    <PackageReference Include="Xamarin.GooglePlayServices.Tasks" Version="71.1601.1" />
    <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
    <PackageReference Include="Xamarin.Forms" Version="4.6.0.967" />
    <PackageReference Include="ZXing.Net.Mobile" Version="2.4.1" />
    <PackageReference Include="ZXing.Net.Mobile.Forms" Version="2.4.1" />

Reproduction Link

Will try get one going but can you please start investigating on stack trace.

Workaround

None as of yet

samhouts commented 4 years ago

This is probably due to the linker removing your splash page. Please review this documentation: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker Thanks!

acuntex commented 4 years ago

@samhouts It could be a general problem that Xamarin.Forms somehow asks for this specific constructor.

I created a Repro here: https://github.com/acuntex/PancakeViewBug_TitleView

Workaround is documented here: https://github.com/sthewissen/Xamarin.Forms.PancakeView/issues/113

And the workaround is also dangerous because the DependencyResolver of Xamarin.Forms (https://github.com/xamarin/Xamarin.Forms/blob/719fc7a604ff0cce8922d717c99bfb0fa17e35e0/Xamarin.Forms.Core/DependencyResolver.cs) has a pretty dirty workaround in line 50, which checks if the constructor has two parameters (without any type checking) and then fails because it does not match. (Just a little appeal to stop fixing bugs with workarounds that require further workarounds that require further workarounds that..)

I urge you to not dismiss this problem as some "linker issue" because it is not.

EDMIStephen commented 4 years ago

@samhouts It could be a general problem that Xamarin.Forms somehow asks for this specific constructor.

I created a Repro here: https://github.com/acuntex/PancakeViewBug_TitleView

Workaround is documented here: sthewissen/Xamarin.Forms.PancakeView#113

And the workaround is also dangerous because the DependencyResolver of Xamarin.Forms (https://github.com/xamarin/Xamarin.Forms/blob/719fc7a604ff0cce8922d717c99bfb0fa17e35e0/Xamarin.Forms.Core/DependencyResolver.cs) has a pretty dirty workaround in line 50, which checks if the constructor has two parameters (without any type checking) and then fails because it does not match. (Just a little appeal to stop fixing bugs with workarounds that require further workarounds that require further workarounds that..)

I urge you to not dismiss this problem as some "linker issue" because it is not.

For us I think in the end it was a Xamarin Android bug related to hybrid AOT. https://github.com/xamarin/xamarin-android/pull/4850

We manually made the change to src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets from that PR and it seemed to resolve the issue. We also needed to support armv7a & arm64-v8a due to this bug: https://github.com/xamarin/xamarin-android/issues/1218