The app is working just fine when using support library v23.1.1 plugin and run under Android 4.4.4 (API 19):
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
however when I build it using newer version (23.2) of android support library it crashes:
XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
This happens when the app wants to inflate an alert dialog with a simple custom view. The custom view uses an XML file containing a <shape>
tag as one of its drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid
android:color="@android:color/white" >
</solid>
<corners
android:radius="5dp">
</corners>
<stroke android:width="1dp" android:color="@color/AppColor" />
</shape>
Though I can't specifically pinpoint this SVG based drawable in the crash logs, but my guess is since Google introduced support for VectorDrawables
, it somehow clashes with my app.
Any hint or input on how to pinpoint the culprit is appreciated.
I ran into a similar issue. I was getting the same error because I was still using the android:src attribute instead of app:srcCompat when setting the source of my ImageView
Changing this attribute everywhere you're referencing a vector drawable will fix your issue.
Old:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add" />
New:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_add" />
It turned out there were two separate issues:
RadioButton
in my XML files. Changing it to android.support.v7.widget.AppCompatRadioButton
fixed the problem.Second, as the blog post was suggesting I had to wrap some of the drawables into container drawables so the support library could use them when doing vector based drawing. For example, in one of my custom buttons, I had vector based background saved in dialog_bg.xml
, button_round_bg.xml
and button_round_bg_2.xml
.
To fix that I had to put them in one of the containers (such as State list, Inset or LevelList). This wrapper was saved to a filed called vector_wrapper.xlm
:
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/dialog_bg"
android:maxLevel="1"
android:minLevel="1" />
<item
android:drawable="@drawable/button_round_bg"
android:maxLevel="2"
android:minLevel="2" />
<item
android:drawable="@drawable/button_round_bg_2"
android:maxLevel="3"
android:minLevel="3" />
</level-list>
Now I would change my custom button's background to say
<customButton
android:background="@drawable/vector_wrapper"
</customButton>
Since the wrapper now has three drawables, I can select them in the Java code according to my needs:
customButton btnSave = (customButton) view.findViewById(R.id.btnSave);
btnSave.getBackground().setLevel(3);
You do not need to the container wrapper if your view is Image
-based view as the other answer by @themichaelscott is suggesting, in that case just change the src to app:srcCompat="@drawable/ic_add"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With