android: [net7] System.NotSupportedException: no Java peer type found
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
7.0.102
Description
After the fix in https://github.com/xamarin/xamarin-android/issues/7473, while the build now passes, I’m getting this runtime exception:
System.NotSupportedException: Cannot create instance of type 'Windows.UI.Xaml.NativeApplication+ActivityCallbacks': no Java peer type found.
Steps to Reproduce
dotnet new install Uno.ProjectTemplates.Dotnetdotnet new unoapp -o testapp -f net7.0cd testapp\testapp.Mobiledotnet build -f net7.0-android -c Release
Did you find any workaround?
Setting the RuntimeIdentifier to a single architecture works around the issue:
<RuntimeIdentifier Condition="'$(TargetFramework)' == 'net7.0-android'">android-x64</RuntimeIdentifier>
But it is not a viable workaround as it does not allow for creating valid store packages.
Relevant log output
01-24 15:08:11.453 26988 26988 I MonoDroid: android.runtime.JavaProxyThrowable: System.NotSupportedException: Cannot create instance of type 'Windows.UI.Xaml.NativeApplication+ActivityCallbacks': no Java peer type found.
01-24 15:08:11.453 26988 26988 I MonoDroid: at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type )
01-24 15:08:11.453 26988 26988 I MonoDroid: at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type )
01-24 15:08:11.453 26988 26988 I MonoDroid: at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String , Type , JniArgumentValue* )
01-24 15:08:11.453 26988 26988 I MonoDroid: at Java.Lang.Object..ctor()
01-24 15:08:11.453 26988 26988 I MonoDroid: at Windows.UI.Xaml.NativeApplication.ActivityCallbacks..ctor(NativeApplication )
01-24 15:08:11.453 26988 26988 I MonoDroid: at Windows.UI.Xaml.NativeApplication.OnCreate()
01-24 15:08:11.453 26988 26988 I MonoDroid: at Android.App.Application.n_OnCreate(IntPtr , IntPtr )
01-24 15:08:11.453 26988 26988 I MonoDroid: at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
01-24 15:08:11.453 26988 26988 I MonoDroid: at crc64122dcf5ad656876d.NativeApplication.n_onCreate(Native Method)
01-24 15:08:11.453 26988 26988 I MonoDroid: at crc64122dcf5ad656876d.NativeApplication.onCreate(NativeApplication.java:26)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1223)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6766)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.app.ActivityThread.access$1500(ActivityThread.java:256)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.os.Handler.dispatchMessage(Handler.java:106)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.os.Looper.loopOnce(Looper.java:201)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.os.Looper.loop(Looper.java:288)
01-24 15:08:11.453 26988 26988 I MonoDroid: at android.app.ActivityThread.main(ActivityThread.java:7874)
01-24 15:08:11.453 26988 26988 I MonoDroid: at java.lang.reflect.Method.invoke(Native Method)
01-24 15:08:11.453 26988 26988 I MonoDroid: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
01-24 15:08:11.453 26988 26988 I MonoDroid: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
01-24 15:08:11.453 26988 26988 I MonoDroid:
01-24 15:08:11.453 26988 26988 I MonoDroid: --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 24 (14 by maintainers)
This should be fixed via 929e701241 (main), c5a84b80e71d875a5aab91db361b15a7bc7630e0 (net7), and the most recent comment.
Closing.
Great! I would still like to figure out what is going wrong here…
It seems like there is a problem with typemaps and assemblies that are architecture-specific, but they seem to work fine in the simple case.
Good news, avoiding
IntPtr.Sizedoes fix the issue, presumably because the assemblies can now actually be shared across architectures. Thanks for the hints @dellis1972 @jonathanpeppers, it was very useful!!Marshal.SizeOf()(or some other API) probably would also work around the problem, they have the rule for inliningIntPtr.Sizehere:https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.64bit.xml