Bug 41489 - [Xamarin.Android.Support.Animated.Vector.Drawable - API 19]Android.Views.InflateException: Binary XML file line #1: Error inflating class ImageView
Summary: [Xamarin.Android.Support.Animated.Vector.Drawable - API 19]Android.Views.Infl...
Status: RESOLVED FIXED
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Staging (addons.xamstage.com)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2016-06-03 16:18 UTC by Jon Douglas [MSFT]
Modified: 2018-01-22 03:48 UTC (History)
5 users (show)

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


Attachments
Screenshot of the exception (164.80 KB, image/png)
2016-09-07 10:14 UTC, Mauro P.
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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jon Douglas [MSFT] 2016-06-03 16:18:24 UTC
Description:

The Xamarin.Android.Support.Animated.Vector.Drawable NuGet package fails to inflate the ImageView class on the current beta package(23.4.0-beta1) running API 19(kitkat). Here is the following stack trace:

06-03 12:04:09.572 E/mono-rt ( 2550): [ERROR] FATAL UNHANDLED EXCEPTION: Android.Views.InflateException: Binary XML file line #1: Error inflating class ImageView ---> Android.Content.Res.Resources+NotFoundException: File res/drawable/vector.xml from drawable resource ID #0x7f02004d ---> Org.XmlPull.V1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
06-03 12:04:09.572 E/mono-rt ( 2550): 
06-03 12:04:09.572 E/mono-rt ( 2550):   --- End of managed exception stack trace ---
06-03 12:04:09.572 E/mono-rt ( 2550): org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.content.res.Resources.loadDrawable(Resources.java:2097)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.content.res.Resources.getDrawable(Resources.java:700)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:49)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:65)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at md583509f93867fdff63bd00c0f64c46fe7.MainActivity.n_onCreate(Native Method)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at md583509f93867fdff63bd00c0f64c46fe7.MainActivity.onCreate(MainActivity.java:28)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.Activity.performCreate(Activity.java:5231)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.os.Handler.dispatchMessage(Handler.java:102)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.os.Looper.loop(Looper.java:136)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at java.lang.reflect.Method.invokeNative(Native Method)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at java.lang.reflect.Method.invoke(Method.java:515)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at dalvik.system.NativeStart.main(Native Method)
06-03 12:04:09.572 E/mono-rt ( 2550): 
06-03 12:04:09.572 E/mono-rt ( 2550):   --- End of inner exception stack trace ---
06-03 12:04:09.572 E/mono-rt ( 2550): 
06-03 12:04:09.572 E/mono-rt ( 2550):   --- End of managed exception stack trace ---
06-03 12:04:09.572 E/mono-rt ( 2550): android.content.res.Resources$NotFoundException: File res/drawable/vector.xml from drawable resource ID #0x7f02004d
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.content.res.Resources.loadDrawable(Resources.java:2101)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.content.res.Resources.getDrawable(Resources.java:700)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
06-03 12:04:09.572 E/mono-rt ( 2550): 	at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323

However a few notes to make are:

1. This works on newer APIs like API 23.

2. This works if using the current stable package(23.3.0) on all APIs

Thus I would consider this a potential regression given the nature that it worked in the 23.3.0 package and does not with the 23.4.0-beta package.

*Reproduction:

https://www.dropbox.com/sh/pvhqtnzy44rlzg4/AABdsWKGdzTYtr3Kz8jfeiQba?dl=0

1. Clear the obj/bin folders
2. Deploy to an API 19 device (Replicated with a Google emulator)
3. Run into the same stack trace

*Version Information:

Microsoft Visual Studio Professional 2015
Version 14.0.25123.00 Update 2
Microsoft .NET Framework
Version 4.6.01038

Xamarin   4.0.4.4 (a9c7826)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.0.4.0 (ee215fc)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   9.6.2.2 (be25da5)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Jon Douglas [MSFT] 2016-07-01 16:15:19 UTC
It looks like this is a bug in the 23.4.0 binding as it works also in a native java project with the support-vector-drawable:23.4.0 package.
Comment 3 Paul Roy 2016-09-07 08:50:07 UTC
Any news on this?
Comment 4 Mauro P. 2016-09-07 10:07:49 UTC
I have the same bug.
Xamarin.Android.Support.Vector.Drawable 23.4.0.2, on API 19 it doesn't work, on API 21 and higher it works.

Calling:
Drawable d = ContextCompat.GetDrawable(Context, Resource.Drawable.ic_circle_w);

I obtain:
android.content.res.Resources$NotFoundException: File res/drawable/ic_circle_w.xml from drawable resource ID #0x7f02008b
...
...
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
Comment 5 Mauro P. 2016-09-07 10:14:11 UTC
Created attachment 17358 [details]
Screenshot of the exception
Comment 6 Mauro P. 2016-09-07 10:43:35 UTC
It doesn't work also with version 23.3.0 on API 19
Comment 7 Jon Dick 2016-09-07 16:03:02 UTC
I pulled the sample down, updated the nuget packages to v23.4.0.1 and it runs fine on an API Level 10 device, and an API Level 19 emulator.

Please update your nuget packages.
Comment 8 Paul Roy 2016-09-07 16:08:46 UTC
I am sorry to disappoint you but my packages are up to date.

This happens (and is explicitely said so) because I have an ImageView in my launchscreen layout.

Here it is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/my_green">
    <ImageView
        android:src="@drawable/logo_my_white"
        android:id="@+id/logoImageView"
        android:layout_centerInParent="true"
        android:layout_width="200dp"
        android:layout_height="200dp" />
    <WebView
        android:layout_width="200dp"
        android:layout_centerInParent="true"
        android:layout_height="200dp"
        android:id="@+id/webView" />
</RelativeLayout>
Comment 9 Mauro P. 2016-09-07 16:13:53 UTC
Updating the nuget packages is the first thing I did, and I tried twice restoring my repository and doing it again.
Comment 10 Jon Dick 2016-09-07 16:14:27 UTC
Paul, assuming you're trying to load a vector into your ImageView, you must use the srcCompat attribute instead of src, as mentioned here: http://stackoverflow.com/a/35645353/93175
Comment 11 Jon Dick 2016-09-07 16:27:40 UTC
Mauro, you may want to set this code to enable using resources from vector files via support:

Android.Support.V7.App.AppCompatDelegate.CompatVectorFromResourcesEnabled = true;
Comment 12 Paul Roy 2016-09-07 16:30:55 UTC
Indeed!

I will test asap to see if that solves the issue for me. Thanks for you quick answers.

But why does it only crashes on API 19? While working on other APIs?
Comment 13 Jon Dick 2016-09-07 16:33:43 UTC
Paul, it should have failed in < API Level 19 as well.  In API Level 21, vector support was added to Android, so it works on API Level 21+ with no changes, since the support library would just switch to the native implementation at that point.
Comment 14 Paul Roy 2016-09-07 16:36:13 UTC
Perfect explanation. It all becomes clear now.
Comment 15 Paul Roy 2016-09-07 17:18:32 UTC
This indeed fixed the issue
Comment 16 Mauro P. 2016-09-08 08:14:18 UTC
Thank you Jon, it worked like a charm.
I already made an attempt with that CompatVectorFromResourcesEnabled found somewhere on an Android forum, but maybe when I tried I still had the previous version of the support library and that property didn't exist so I thought it wasn't related.
Thank you again.
Comment 17 Jon Dick 2016-09-08 14:06:17 UTC
Resolved
Comment 18 Mauro P. 2016-12-15 12:19:13 UTC
Hi Jon, sorry to bother you again but I have another problem with Support Library and Vector Drawables and I wasn't able to solve it looking on the web for hours. They look very similar so I write directly here hoping that they are related.

I updated the API target of my Xamarin Android app to 24 and updated the Xamarin Android.Support to 24.2.1, but my app crashes on pre-lollipop devices (a Samsung with API 19) at the opening of first Activity:
[VdcInflateDelegate] org.xmlpull.v1.XmlPullParserException: Binary XML file line #15<vector> tag requires viewportWidth > 0

Android.Content.Res.Resources+NotFoundException has been thrwown
File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052

I don't think it's related but I enabled ProGuard to solve the tricky problem 65536 and I had to replace the ProGuard because it didn't work:
http://stackoverflow.com/questions/39514518/xamarin-android-proguard-unsupported-class-version-number-52-0
Comment 19 Jon Douglas [MSFT] 2016-12-15 15:58:48 UTC
@Maruo P.

Please open up a Stack Overflow or Xamarin Forums post about this issue. It is advised that any further communication on this bug is related to the bug itself and not other issues.

You are most likely running into this issue:

https://stackoverflow.com/questions/41105845/android-crash-on-app-startup-after-xamarin-support-library-update-from-24-2-1-to#comment69422082_41105845

http://stackoverflow.com/questions/39091521/vector-drawables-flag-doesnt-work-on-support-library-24
Comment 20 JesseZhang 2018-01-22 03:48:24 UTC
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Annotations" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Compat" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Core.UI" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Core.Utils" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Design" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Fragment" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Media.Compat" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Transition" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.v4" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="25.4.0.2" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="25.4.0.2" targetFramework="monoandroid71" />



show error: 

 --- End of managed Org.XmlPull.V1.XmlPullParserException stack trace ---
org.xmlpull.v1.XmlPullParserException: Binary XML file line #15: invalid drawable tag vector
	at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
	at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
	at android.content.res.Resources.loadDrawable(Resources.java:2092)
	at android.content.res.Resources.getDrawable(Resources.java:700)
	at android.support.v7.widget.VectorEnabledTintResources.superGetDrawable(VectorEnabledTintResources.java:74)
	at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:437)
	at android.support.v7.widget.VectorEnabledTintResources.getDrawable(VectorEnabledTintResources.java:67)
	at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202)
	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
	at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:711)
	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
	at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
	at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:131)
	at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:155)
	at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
	at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
	at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
	at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
	at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
	at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
	at md5d4650294d969630d3e35ba1924da8f51.LogoActivity.n_onCreate(Native Method)
	at md5d4650294d969630d3e35ba1924da8f51.LogoActivity.onCreate(LogoActivity.java:40)
	at android.app.Activity.performCreate(Activity.java:5231)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
	at android.app.ActivityThread.access$800(ActivityThread.java:135)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:136)
	at android.app.ActivityThread.main(ActivityThread.java:5001)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:515)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
	at dalvik.system.NativeStart.main(Native Method)