'Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.v7.widget.Toolbar'

After updating my app from FormsApplicationActivity to FormsAppCompatActivity, I get the following exception thrown in base.OnCreate(bundle):

Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.v7.widget.Toolbar'

This seems to come from my layout/Toolbar.xml file, which I have not changed from the default.

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

The funny thing is, if I create a new project, it works. As far as I can tell, everything is exactly the same between my old upgraded project and the brand new one.

Things I've tried:

  • Add Theme = "@style/MainTheme" to the [Activity] attribute
  • Add android:theme="@style/MainTheme" to the <application> tag of AndroidManifest.xml
  • Add
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;
    
    to OnCreate()
  • Copy styles.xml, colors.xml, Toolbar.xml, Tabbar.xml from the working project into the old project
  • Clean solution + delete bin/obj folders + rebuild
  • Doing a diff between the .csproj files and replacing almost everything from the working file into the bad file
  • Completely uninstall Xamarin Forms and all AndroidX dependencies, then reinstall from NuGet. The AndroidX dependencies were not readded, which matches the newly created project

None of it worked. How do I fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source