Bug 41380 - Error inflating class android.support.v7.widget.Toolbar after updating to v7.AppCompat Version 23.3.0
Summary: Error inflating class android.support.v7.widget.Toolbar after updating to v7....
Status: REOPENED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: unspecified
Hardware: All All
: High normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2016-05-30 14:00 UTC by Andrea
Modified: 2017-07-14 19:30 UTC (History)
21 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:


Attachments
screenshot (862.81 KB, image/jpeg)
2017-01-26 07:24 UTC, Manabu Nakazawa
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 41380 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
REOPENED

Description Andrea 2016-05-30 14:00:21 UTC
I have a Xamarin.Forms 2.3.0.38-pre2 project. 
After I upgraded Xamarin.Android.Support.v7.AppCompat 23.0.1.3 to 23.3.0 this has started throwing Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.toolbar exception.

//MainActivity
FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
...

//layout.toolbar
<?xml version="1.0" encoding="utf-8"?>
  <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
...
Comment 1 Paul DiPietro [MSFT] 2016-06-02 17:57:51 UTC
Could you possibly put together a reproduction sample? It would be much appreciated. For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d
Comment 2 Andrea 2016-06-03 05:04:56 UTC
Hi Paul, I tried to reproduce the problem in a new project without success, it works. But still present in my project. I tried to remo e the support libraries and re-install without success. I also found this old link.
https://forums.xamarin.com/discussion/36875/android-support-v7-error-after-updating
Comment 3 Andrea 2016-06-16 08:11:22 UTC
Any update?
I upgraded to 2.3.0.46 pre3 (I need beta channel for some features) and the problem still persists...
I also tried to force remove Xamarin.Androdi.Support.v7.AppCompact nuget package and re-add it without success..
Comment 4 Jason DeBoever 2016-07-21 19:22:52 UTC
This error seems to potentially have a number of causes, but at least one that i haven't seen reported elsewhere is a missing 

android:theme="@style/MyTheme" 

 from the application tag in android manifest (replace MyTheme with whatever your theme name is).  A couple interesting things here:

1) Under normal circumstances a missing theme gives you an error saying "you need to use a theme.appcompat theme" which is pretty descriptive

2) If you are using FormsAppCompatActivity.ToolbarResource _and_ if that file is using "?attr/actionBarSize" (or possibly any "?attr/") then you will instead get the "inflating Toolbar..." error

Going to try to reproduce this on a non-forms Android project and will add another comment with results
Comment 5 Jason DeBoever 2016-07-21 21:28:48 UTC
I can _not_ recreate under any reasonably normal circumstances in a xamarin.android (non-forms) project.
Comment 6 Jason DeBoever 2016-07-21 22:13:41 UTC
Correction:  This can be reproduced on xamarin.android.

Steps to reproduce:

1) Be using AppCompatActivity
2) Omit a theme declaration from your androidManifest

(Normally this produced a nice respectable error)

3) Add an toolbar.axml that uses 
  android:layout_height="?attr/actionBarSize"

4) Add toolbar to activity through code (NOT THROUGH AXML!) like so:
  var toolbar = LayoutInflater.Inflate(Resource.Layout.toolbar, null, false);

This is the technique XF uses and this causes the exception.  If you do not use any "?attr" values _OR_ if you load your toolbar through AXML includes you get a nice respectable error message about adding a theme.  

In all of these conditions, adding a compat theme to the Manifest fixes all exceptions.
Comment 7 Rui Marinho 2016-08-04 15:57:12 UTC
Hi Andrea please provide your themes file and your main activity code.

This seems a problem where is something missing in your project that we can't identify without more info. 

Thanks

Warm Regards
Xamarin Forms Team
Comment 8 James Montemagno [MSFT] 2016-08-07 04:59:49 UTC
This doesn't seem like a bug as you must set the Theme in the Android Manifest as documented:
https://developer.xamarin.com/guides/xamarin-forms/platform-features/android/appcompat/#4._Update_AndroidManifest.xml

Easy to miss though.
Comment 9 Samantha Houts [MSFT] 2016-09-30 18:28:08 UTC
@Andrea,

Were you able to resolve this issue with the suggestions made in the ticket?
Comment 10 Korayem 2016-09-30 19:55:57 UTC
In my case, it was a problem with my android styles not being loaded correctly
Comment 11 Michael Rumpler 2016-11-22 17:15:35 UTC
I was missing the theme in the AndroidManifest. Adding it fixed the error for me.
But you have to be lucky to find this bug report. The error message doesn't help at all.
Comment 12 Samantha Houts [MSFT] 2016-12-01 18:08:39 UTC
This appears to be answered. Please reopen this report if adding the theme in the Android Manifest as documented in https://developer.xamarin.com/guides/xamarin-forms/platform-features/android/appcompat/#4._Update_AndroidManifest.xml does not resolve the issue.

Thank you!
Comment 13 nicolas.audemard 2017-01-05 16:05:48 UTC
Hello,

same problem with a new crossplatform Portable project with API 20, 21, 22
With last version of xamarin.Forms.

Works normaly on API 19 or API 23.

I've follow the link recommended without sucess.
Comment 14 Chris King 2017-01-06 21:27:21 UTC
Nicolas, could you please attach the project which you are using to reproduce this error? Did you have to upgrade from a previous project or did you start with the template project? If you had to upgrade, could you please provide the project before the upgrade? 

Thanks for taking the time to report this issue!

Warm regards,
XFT
Comment 15 nicolas.audemard 2017-01-09 08:23:40 UTC
Hello Chris,

Just make a new project in cross-Platform Blank App (Xamarin.form.portable) without touching anything (in the project attached i removed all the non Droid sub-project, but in my main project there are used).

I've all the latest upgrade from xamarin for visual studio + Xamarin dll.

Thx for the help

Attchment : http://www.sendbox.fr/4382d4f6d6bff6a1/Test-App2.rar
Comment 16 realspkr 2017-01-12 17:15:17 UTC
Hi Chris,

I have this issue when I create a new project in VS2015 from the "Blank Xaml App (Xamarin.Forms Portable).

Adam
Comment 17 realspkr 2017-01-12 17:31:23 UTC
Hi Samantha,

After creating a new project from the Blank Xaml App, I applied changes from the page you included and the results are the same exception.

Adam
Comment 18 Patrick 2017-01-16 04:20:38 UTC
I am seeing the same result after following the same steps as Adam. I'm using a Moto E running Android 5.1, and indicated this in properties dialog for both the Compile using and Min Android to target and Target Android version. I can deploy the app to the Andriod_Accelerated_X86 vm running Android 6 and SDK level 23. Just ran the update on the Moto E as well so the OS on the device s/b up to date. Any help would be appreciated.
Comment 19 Saskia 2017-01-16 11:27:59 UTC
Hello

I also created a new project in VS2015 from the "Blank Xaml App (Xamarin.Forms Portable).
The error was thrown even with the theme added to the manifest.

The created app used xamarin.forms version 2.3.3.180.

After changing this to xamarin.forms version 2.3.3.175, the error was gone. 

Kind regards, Saskia
Comment 20 manoj 2017-01-18 07:04:23 UTC
I GOT THE SAME ERROR, BUT TRYING ALL DIFFERENT THINGS SUGGESTED IN DIFFERENT THREADS IN DIFFERENT LOCATIONS I TRIED BELOW.

THIS WORKED FOR ME.

DELETED "Xamarin.Android.Support.v7.AppCompat" FOLDER FROM LOCATION 
"C:\Users\\AppData\Local\Xamarin"

THIS IS FOR WINDOWS NOT SURE ABOUT IF YOU ARE DEVELOPING IN MAC MACHINE
Comment 21 Manabu Nakazawa 2017-01-26 07:24:00 UTC
Created attachment 19484 [details]
screenshot

I also faced this error when I ran the Android demo of the following library ( master's HEAD (8567b5e)).

https://github.com/alexrainman/CarouselView

It always happened when I ran it on API 21 physical device (LG-D821).
But it didn't happened on API 25 simulator (Nexus 6P).

Can you guys reproduce it?
Comment 22 savandavande 2017-02-05 01:13:46 UTC
Comments 19 worked for me. 


Thanks,
Savan
Comment 23 Samantha Houts [MSFT] 2017-02-14 01:18:50 UTC
You may have a mismatch with the packages installed. For example, the scenario in Comment 21 can be resolved by reinstalling the Xamarin.Android.Support packages on both the Demo.Droid project and the CarouselView.FormsPlugin.Android project; this will install the packages targeting monoandroid70.
Comment 24 Mikayla Hutchinson [MSFT] 2017-06-19 19:12:42 UTC
Reassigning to the XA build tooling because 

a) the need to do a clean build implies that something is broken in incremental builds
b) there should be a build-time error message for this problem