-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Incompatible ButtonHandler when embedding MAUI page in .NET Android-project #7549
Comments
I think we need to improve the exception message here. This can also mean that for some reason when creating that button it hit an exception. Which could be a variety of things. Does the inner exception have any more information? if you enable all CLR exceptions in the |
Here's the entire stack trace: Microsoft.Maui.Platform.ToPlatformException: Microsoft.Maui.Handlers.ButtonHandler found for Microsoft.Maui.Controls.Button is incompatible ---> Java.Lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant). at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:line 12324 at Java.Interop.JniPeerMembers.JniInstanceMethods.FinishCreateInstance(String constructorSignature, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:line 142 at Google.Android.Material.Button.MaterialButton..ctor(Context context) in C:\a_work\1\s\generated\com.google.android.material.material\obj\Release\net6.0-android\generated\src\Google.Android.Material.Button.MaterialButton.cs:line 385 at Microsoft.Maui.Platform.MauiMaterialButton..ctor(Context context) in D:\a_work\1\s\src\Core\src\Platform\Android\MauiMaterialButton.cs:line 13 at Microsoft.Maui.Handlers.ButtonHandler.CreatePlatformView() in D:\a_work\1\s\src\Core\src\Handlers\Button\ButtonHandler.Android.cs:line 27 at Microsoft.Maui.Handlers.ViewHandler |
If it helps anyone, getting at the inner exception does tell you what is wrong. For me it came up through the AndroidEnvironment.UnhandledExceptionRaiser event where I could capture it. Everyone's issue may be different. Mine was a style enforcement problem and looks to be a pretty straightforward issue. Well straightforward once I saw what it really is: --- End of managed Java.Lang.IllegalArgumentException stack trace --- |
I've faced the same issue in our tests for Android. What are you thinking about fix? |
We are facing this issue too and are currently using Labels with Tap Gestures instead of buttons due to this issue. |
I'm running into this without trying to use embedding, with the same style enforcement backtrace. I'm porting a Xamarin.Forms app to MAUI, adding my code to a MAUI template app. My theme is "@style/Maui.SplashTheme". It seems like that Theme has a Material Theme as a parent, so I'm not sure what's going wrong: https://github.com/dotnet/maui/blob/c1439acf4dfeb0e5a6f56583d6a1860a12ff4a6f/src/Core/src/Platform/Android/Resources/values/styles.xml The template app was functioning OK prior to me replacing the Android Application and Maui Programs with the ported code from my Forms app. Is it possible that something about my ported Forms code is incompatible with material theming? Update - as everyone said, you really do want to set an exception catchpoint on System.Exception to get at the inner exception. Doing so points me to the culprit, in my code. |
I think there might be some issue with the project settings for android. I got similar error while starting the app. But, when I launched same app after installing to android device, t Android OS stated that, the application is built for older version of OS, so ask developer for updated version of the app. But it was latest so go to settings and changed setting here and there and I got problem resolved. 1] I changed targetSdkVersion and minSdkVersion to minimum that was 21 in my case |
Still running into this issue in my project, but now I get the underlying error message telling me that I need to set my app's theme to Theme.MaterialComponents. Tried it for my app, but it keeps throwing the error whenever a page with a button is trying to be rendered. When I try to do this in a clean File -> New Project and enable MAUI embedding it seems to work. Might have to try out some of @HemalPatel1111 's workarounds. |
I was facing same issue when migrating to MAUI. In the end, it was the Resources\values\styles.xml in Android project, that made the conflict. |
I think all the comments are saying you found the issue to be the themes and you were able to fix it? |
Hi @andreas-nesheim. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. |
Description
I'm testing out embedding MAUI pages into a new .NET 6 Android-project using this guide. When I try to embed a page that contains a Button control it crashes with the following exception:
Microsoft.Maui.Platform.ToPlatformException: 'Microsoft.Maui.Handlers.ButtonHandler found for Microsoft.Maui.Controls.Button is incompatible'
. This happens at the following statement:When I test the same thing on a .NET 6 iOS-project, it works fine.
Steps to Reproduce
.ToPlatform(context)
on the new pageVersion with bug
6.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12
Did you find any workaround?
Had to comment out the Button.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: