Stack Exchange
Use of drawable vectors SDK < 21: Binary XML file line #68: Error inflating class <unknown> invalid drawable tag vector
I'm using android studio 3.1.2 on Linux, with the following setup:
compileSdkVersion 27
buildToolsVersion '27.0.3'
minSdkVersion 16
targetSdkVersion 19
Gradle version: 4.4
Android plugin version: 3.1.2

My project uses the following dependencies:
implementation 'com.google.android.exoplayer:exoplayer-core:2.8.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-crash:15.0.2'
implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.google.android.gms:play-services-plus:15.0.1'
implementation 'com.android.support:palette-v7:27.1.1'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'

On pre Lollipop devices - SDK < 21 , I'm getting the following exception:


E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{ro.aripisprecer.radiocrestin/ro.aripisprecer.radiocrestin.HomeScreen}: android.view.InflateException: Binary XML file line #68: Error inflating class <unknown>

Caused by: android.view.InflateException: Binary XML file line #68: Error inflating class <unknown>

Caused by: java.lang.reflect.InvocationTargetException
                         at java.lang.reflect.Constructor.constructNative(Native Method)
                         at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                         at android.view.LayoutInflater.createView(LayoutInflater.java:595)
                         at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                         at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670) 
                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695) 
                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) 
                         at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                         at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                         at ro.aripisprecer.radiocrestin.PlayRadio.onCreateView(PlayRadio.java:350) 
                         at android.app.Fragment.performCreateView(Fragment.java:1700) 
                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890) 
                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) 
                         at android.app.BackStackRecord.run(BackStackRecord.java:684) 
                         at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 
                         at android.app.Activity.performStart(Activity.java:5240) 
                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168) 
                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                         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:5017) 
                         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:779) 
                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                         at dalvik.system.NativeStart.main(Native Method) 
                      
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_share_black_24dp.xml from drawable resource ID #0x7f08009b
                         at android.content.res.Resources.loadDrawable(Resources.java:2101)
                         at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                         at android.view.View.<init>(View.java:3554)
                         at android.view.View.<init>(View.java:3484)
                         at java.lang.reflect.Constructor.constructNative(Native Method) 
                         at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                         at android.view.LayoutInflater.createView(LayoutInflater.java:595) 
                         at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                         at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670) 
                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695) 
                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) 
                         at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                         at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                         at ro.aripisprecer.radiocrestin.PlayRadio.onCreateView(PlayRadio.java:350) 
                         at android.app.Fragment.performCreateView(Fragment.java:1700) 
                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890) 
                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) 
                         at android.app.BackStackRecord.run(BackStackRecord.java:684) 
                         at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 
                         at android.app.Activity.performStart(Activity.java:5240) 
                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168) 
                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                         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:5017) 
                         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:779) 
                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                         at dalvik.system.NativeStart.main(Native Method) 

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: 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:2097)
                         at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
                         at android.view.View.<init>(View.java:3554) 
                         at android.view.View.<init>(View.java:3484) 
                         at java.lang.reflect.Constructor.constructNative(Native Method) 
                         at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                         at android.view.LayoutInflater.createView(LayoutInflater.java:595) 
                         at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
                         at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670) 
                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695) 
                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) 
                         at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                         at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                         at ro.aripisprecer.radiocrestin.PlayRadio.onCreateView(PlayRadio.java:350) 
                         at android.app.Fragment.performCreateView(Fragment.java:1700) 
                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890) 
                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) 
                         at android.app.BackStackRecord.run(BackStackRecord.java:684) 
                         at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 
                         at android.app.Activity.performStart(Activity.java:5240) 
                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168) 
                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                         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:5017) 
                         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:779) 
                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                         at dalvik.system.NativeStart.main(Native Method) 



I have followed other suggestions and replaced: 

android:src to app:srcCompat,  
included vectorDrawables.useSupportLibrary = true in the build.gradle, and 
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
in the public class HomeScreen extends AppCompatActivity{

But this didn't solved my problem.
See a snippet from my homescreen_layout.xml starting from line #68
 <View
    android:layout_width="14dp"
    android:layout_height="14dp"
    android:layout_marginBottom="6dp"
    android:layout_marginEnd="5dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/ic_share_black_24dp"
    app:layout_constraintBottom_toBottomOf="@+id/music_image"
    app:layout_constraintRight_toRightOf="@+id/music_image" />

And this is the content of the ic_share_black_24dp.xml file:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:width="14dp"
android:height="14dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
tools:ignore="VectorRaster">

<path
    android:fillColor="@color/red_color_toolbar"
    android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />


What am I doing wrong here? Any help is appreciated.
Thank you!

What happens when you comment out that class Binary XML file line #68 Does your project run?

If i comment out the class starting at the line #68 , it moves to the next one, line #128:
<ImageButton
.....
android:scaleType="fitXY"
app:srcCompat="@drawable/report_btn_draw"
if i comment every imagebutton i get a null ponter exception
java.lang.RuntimeException: Unable to start activity ComponentInfo{ro.aripisprecer.radiocrestin/ro.aripisprecer.radiocrestin.HomeScreen}: java.lang.NullPointerException

Okay. I didn't noticed this. Please change your targetSdkVersion 19 to 27 and download latest build tool version 27.0.3 and check it on emulator API 17, (not on API 19, it has some unresolved bugs) See, if that works.

@RohitSharma it is the same error. Could it be that the exceptions comes from somewhere else and not from this xml file?

2 errors are quite evident from your Logcat
 1. Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_share_black_24dp.xml from drawable resource ID #0x7f08009b
 2. Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector

If after upgrade also, you are encountering the same error, then
Try it one by one, whatever works.

Make sure your naming matches since it is not able to find it, I would suggest you to:
a. Invalidate Caches/Restart,  
b. if not, delete .idea & .gradle from your project location
c. if not, delete the resource, clean the project and recreate the resource again
Make sure your ic_share_black_24dp is not used anywhere else in the project, i.e. left drawer panel (navigation menu) & right panel (navigation menu), if it is then rename one of the resource


Also, try it with this vector resource
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

Edit: In your View tag, please change this:
android:background="@drawable/ic_share_black_24dp" 
to this:
app:srcCompat="@drawable/ic_share_black_24dp"

I have followed every step as you described and it seams it coud find the resource, but the problem is with the "vector" tag. I have uploaded the full debug trace, the xml resource and the home screen layout on google drive. You can have a look and maybe you could find something. Please have a look here:
https://drive.google.com/drive/folders/12Obj7dY8yxVAf6YLGEmA4lU35TLSb7mm?usp=sharing

Thanks Marius. Is it also possible to share the whole project, so that I can test it tomorrow.

thanks for the reply. Unfortunately I am not allowed to share the whole app. Would it be possible for you to connect remotely to my computer and check it live?

Sure thing. AnyDesk?

Edited the answer. :)

Should I send you the ID here or as a text file on Google drive?

Hey, please see the document from the google drive. There is my id. I am online, just text me on skype. Thank you!

I'm having a similar issue.  I tried replacing android:background with app:srcCompat which stopped the crashes, however now the views look completely wrong...
