You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI应用Android模拟器初始化报错:InflateException(AppBarLayout)

MAUI Android模拟器初始化抛出Android.Views.InflateException异常

异常信息

Android.Views.InflateException

消息:com.companyname.shvn_guide:layout/flyoutcontent的二进制XML文件第1行:无法加载类com.google.android.material.appbar.AppBarLayout

堆栈跟踪

0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception C#
0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5 C#
0x1E in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:122,26  C#
0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw    C#
0x69 in Java.Interop.JniEnvironment.InstanceMethods.CallObjectMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:11524,5    C#
0x3E in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualObjectMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:867,7    C#
0x4B in Android.Views.LayoutInflater.Inflate at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.LayoutInflater.cs:661,5 C#
0x2B in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutTemplatedContentRenderer.LoadView at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutTemplatedContentRenderer.cs:78,4    C#
0x2B in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutTemplatedContentRenderer..ctor at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutTemplatedContentRenderer.cs:60,4   C#
0x1 in Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.CreateShellFlyoutContentRenderer at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellRenderer.cs:144,4    C#
0x1 in Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.Microsoft.Maui.Controls.Platform.Compatibility.IShellContext.CreateShellFlyoutContentRenderer at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellRenderer.cs:49,4    C#
0x1C in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.AddFlyoutContentToLayoutIfNeeded at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRenderer.cs:249,5   C#
0x68 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.AttachFlyout at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRenderer.cs:231,5   C#
0x3 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.Microsoft.Maui.Controls.Platform.Compatibility.IShellFlyoutRenderer.AttachFlyout at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRenderer.cs:64,4 C#
0x55 in Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.OnElementSet at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellRenderer.cs:211,4   C#
0x1B in Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.SetVirtualView at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellRenderer.cs:194,4 C#
0x7 in Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.Microsoft.Maui.IElementHandler.SetVirtualView at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellRenderer.cs:302,4   C#
0x8B in Microsoft.Maui.Controls.Element.SetHandler at D:\a_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:69,6 C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:19,11    C#
0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:305,5 C#
0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4   C#
0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform at D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:127,4  C#
0x5F in Microsoft.Maui.Platform.ContainerView.SetView at D:\a_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:72,5 C#
0x3 in Microsoft.Maui.Platform.ContainerView.set_CurrentView at D:\a_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:51,11 C#
0x8 in Microsoft.Maui.Platform.ElementExtensions.ToContainerView at D:\a_work\1\s\src\Core\src\Platform\Android\ElementExtensions.cs:11,4  C#
0x1F in Microsoft.Maui.Platform.NavigationRootManager.Connect at D:\a_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationRootManager.cs:56,5  C#
0x26 in Microsoft.Maui.Handlers.WindowHandler.CreateRootViewFromContent at D:\a_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:79,4    C#
0x15 in Microsoft.Maui.Handlers.WindowHandler.MapContent at D:\a_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:24,4   C#
0x21 in Microsoft.Maui.PropertyMapper<Microsoft.Maui.IWindow,Microsoft.Maui.Handlers.IWindowHandler>. at D:\a_work\1\s\src\Core\src\PropertyMapper.cs:172,6    C#
0x17 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore at D:\a_work\1\s\src\Core\src\PropertyMapper.cs:47,4  C#
0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties at D:\a_work\1\s\src\Core\src\PropertyMapper.cs:82,5    C#
0xCB in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView at D:\a_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:79,4    C#
0x8B in Microsoft.Maui.Controls.Element.SetHandler at D:\a_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:69,6 C#
0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:19,11    C#
0xA2 in Microsoft.Maui.Platform.ElementExtensions.SetHandler at D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:156,4 C#
0x3 in Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler at D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:166,4    C#
0x79 in Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow at D:\a_work\1\s\src\Core\src\Platform\Android\ApplicationExtensions.cs:46,4    C#
0x54 in Microsoft.Maui.MauiAppCompatActivity.OnCreate at D:\a_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.cs:32,4 C#
0x11 in Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.App.Activity.cs:2816,4 C#
0x9 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:121,5    C#

环境信息

  • Windows 10 Pro 19045.3324
  • 16 GB内存
  • Visual Studio Community 17.7.3
  • .NET 7.0
  • 模拟器:Pixel 5 API - 33(Android 13 - API 33)

补充说明

异常在App.xaml.cs的App构造函数的InitializeComponent()方法中抛出,此前基于Xamarin开发的同类应用未出现该异常。


解决思路

  • 检查Material Design主题配置:确认AndroidManifest.xml中应用主题是否为Material Components系列(如Theme.MaterialComponents.Light.DarkActionBar),而非传统AppCompat主题,MAUI Android依赖该组件库加载AppBarLayout。
  • 更新MAUI NuGet包:将Microsoft.Maui.Controls、Microsoft.Maui.Controls.Compatibility等相关NuGet包更新至.NET 7对应的最新稳定版本,避免版本不兼容导致的组件缺失。
  • 清理重建项目:
    1. 删除项目目录下的bin和obj文件夹
    2. 在Visual Studio中执行“清理解决方案”→“重建解决方案”
    3. 重启模拟器后重新部署应用
  • 校验自定义Flyout布局:若修改过Flyout模板(flyoutcontent),检查是否错误引用了未导入的Material组件,或组件命名空间是否正确。
  • 更新Android SDK依赖:打开Android SDK Manager,确保已安装最新版Android 13(API 33)组件,以及Google Repository、Android Support Repository等必要依赖。

内容的提问来源于stack exchange,提问作者nissekul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 11:39:51