After change navigation drawer item's icon, app is dead - android

I downloaded icons for navigation drawer items at here
And I changed my drawer item icons. And then, I tried to run my app.
But, my app is not working. It was fine before change icons.
I just moved xml files of icons to drawable-v21 folder.
Here is the message.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hsk.hallymexam, PID: 11979
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.hsk.hallymexam/com.hsk.hallymexam.MainActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
at android.app.ActivityThread.access$900(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.hsk.hallymexam.MainActivity.onCreate(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:5580)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
at android.app.ActivityThread.access$900(ActivityThread.java:170) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5635) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method) 
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:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.hsk.hallymexam.MainActivity.onCreate(MainActivity.java:42) 
at android.app.Activity.performCreate(Activity.java:5580) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
at android.app.ActivityThread.access$900(ActivityThread.java:170) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5635) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020050
at android.content.res.Resources.getValue(Resources.java:2326)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:321)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:495)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436)
at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112)
at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:245)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:169)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:600) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.hsk.hallymexam.MainActivity.onCreate(MainActivity.java:42) 
at android.app.Activity.performCreate(Activity.java:5580) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
at android.app.ActivityThread.access$900(ActivityThread.java:170) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5635) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method)
Did I do something wrong?

first of all, as other people suggesting don't place your icons in mipmap folder. It is a specific folder only for application icon. Place all you icons in drawable folders.
Second, check your drawable folder. If your icons only placed in drawable-v21 then you have a problem, because drawable-v21 used only for devices with api level >= 21. Just replace them to drawable folder
Third, if you using vector graphics and want to support devices with api level < 21, you need to enable supporting of vector drawables. More info here

You need to put all drawer icon into drawable-hdpi,drawable-mdpi,drawable-xhdpi drawable-xxhdpi and drawable-xxxhdpi folder

There are many reasons for this exception:
Icon size too large (in pixels)
Solution : All your drawables used in navigation drawer and other icons should be atmost of 48*48 pixel size.
Improper reference to drawable
Solution : First copy the image (which follows solution-1) and then in android studio, paste it in the drawable root folder.
Improper support of SVG
Solution : follow this link
All your XML drawables should be stored in drawables root folder and not in size specific sub folders for better results.
If you are using SVG files, then follow the link i mentioned above, copying XML files to another API specific folder directly will only increase your problem

I assume that you are using Android Studio IDE
1) If you are using png / jpg icons then put your icons in respective mipmap folder i.e, mipmap-hdpi, mipmap-xhdpi, etc. & then reference it as #mipmap/YOUR_ICON_NAME
2) If you are using XML (vector drawables) files for icons then put your all xml(vector drawables) files in drawable folder instead of drawable-v21 and then reference it as #drawable/YOUR_XML_FILE_NAME
Hope it will help :)

Related

Resource not found exception in android 4.2.2

I have created a theme for splash screen on style.xml file.
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background_96dp</item>
</style>
The splash_background_96dp is a xml drawable.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorWhite"/>
<item android:gravity="center">
<bitmap
android:gravity="fill_horizontal|fill_vertical"
android:src="#drawable/logo1"/>
</item>
</layer-list>
The logo1 is a png file.
I use this theme for splash screen activity in my app. It works on android 7.1.0 but on android 4.2.2 the below exception occurs:
03-04 15:31:02.849 14225-14225/com.sarsabad.sarsabadmanager E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sarsabad.sarsabadmanager/com.sarsabad.sarsabadmanager.ui.SplashActivity}: android.content.res.Resources$NotFoundException: File res/drawable/splash_background_96dp.xml from drawable resource ID #0x7f0700e4
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
at android.app.ActivityThread.access$700(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_background_96dp.xml from drawable resource ID #0x7f0700e4
at android.content.res.Resources.loadDrawable(Resources.java:2842)
at android.content.res.Resources.getDrawable(Resources.java:1521)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:360)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:85)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:128)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70)
at com.sarsabad.sarsabadmanager.ui.SplashActivity.onCreate(SplashActivity.java:39)
at android.app.Activity.performCreate(Activity.java:5283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299) 
at android.app.ActivityThread.access$700(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5283) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #7: <bitmap> requires a valid src attribute
at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:454)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:921)
at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:165)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:921)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)
at android.content.res.Resources.loadDrawable(Resources.java:2839)
at android.content.res.Resources.getDrawable(Resources.java:1521) 
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:360) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198) 
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:85) 
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:128) 
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149) 
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29) 
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183) 
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519) 
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70) 
at com.sarsabad.sarsabadmanager.ui.SplashActivity.onCreate(SplashActivity.java:39) 
at android.app.Activity.performCreate(Activity.java:5283) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299) 
at android.app.ActivityThread.access$700(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5283) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
at dalvik.system.NativeStart.main(Native Method) 
In order to make the logo1 file available, you need to put the image into your drawable folder to be accessed for all Android versions. As I guessed it correctly, the image was in other folder with a higher qualifier (i.e. drawable-v21 in your case).

DexGuard and Vector Drawables

I am using DexGuard to compile my app. My app uses vector drawables. I have all the settings correct, and it works correctly, both in the debug version, and when I use Proguard for the release version. It only crashes in the release version when using DexGuard. So I know it's a DexGuard issue.
I am using DexGuard v7.0 and I cannot update due to license restrictions.
I have added
-keepresourcefiles "res/drawable/**"
-keep class android.support.v7.** { *; }
to my dexguard file for testing purposes and for clearer stacktraces, so we know that is not the issue.
It crashes with following stacktrace;
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lionscribe.myapp/com.lionscribe.elist.main.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020018
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020018
at android.content.res.Resources.loadDrawable(Resources.java:3440)
at android.content.res.Resources.getDrawable(Resources.java:1917)
at o.?.?(:354)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(:193)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(:181)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(:689)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(:186)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(:77)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(:83)
at android.support.v7.app.AppCompatDelegateImplV7.<init>(:146)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(:28)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(:41)
at android.support.v7.app.AppCompatDelegate.create(:193)
at android.support.v7.app.AppCompatDelegate.create(:173)
at android.support.v7.app.AppCompatActivity.getDelegate(:511)
at android.support.v7.app.AppCompatActivity.onCreate(:71)
at o.hF.onCreate(:29)
at com.lionscribe.elist.main.MainActivity.onCreate(:121)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
at android.app.ActivityThread.access$900(ActivityThread.java:175) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5602) 
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:1283) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
at android.content.res.Resources.loadDrawable(Resources.java:3436)
at android.content.res.Resources.getDrawable(Resources.java:1917) 
at o.?.?(:354) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(:193) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(:181) 
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(:689) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(:186) 
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(:77) 
at android.support.v7.app.AppCompatDelegateImplBase.<init>(:83) 
at android.support.v7.app.AppCompatDelegateImplV7.<init>(:146) 
at android.support.v7.app.AppCompatDelegateImplV11.<init>(:28) 
at android.support.v7.app.AppCompatDelegateImplV14.<init>(:41) 
at android.support.v7.app.AppCompatDelegate.create(:193) 
at android.support.v7.app.AppCompatDelegate.create(:173) 
at android.support.v7.app.AppCompatActivity.getDelegate(:511) 
at android.support.v7.app.AppCompatActivity.onCreate(:71) 
at o.hF.onCreate(:29) 
at com.lionscribe.elist.main.MainActivity.onCreate(:121) 
at android.app.Activity.performCreate(Activity.java:5451) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471) 
at android.app.ActivityThread.access$900(ActivityThread.java:175) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5602) 
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:1283) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
at dalvik.system.NativeStart.main(Native Method) 
Upon following the code, I follow that when using DexGuard, the method loadDrawableFromDelegates (called from getDrawable) in android.support.v7.widget.AppCompatDrawableManager is returning null. Therefore getDrawable continues and calls ContextCompat.getDrawable, which does not support Vectors in pre-Lollipop devices, and it returns null with an invalid drawable tag vector log, and therefore causes a ResourcesNotFoundException.
When using the debug version, loadDrawableFromDelegates does return a Drawable, therefore ContextCompat.getDrawable does not get called, and everything works fine.
Does anyone have any ideas how to avoid this. I Googled, and there are others who had similiar issues, but they were mostly appcompat vector setting issues, not DexGuard.
Well after 12 hours of work, I finally figured it out, and all it was is 1 line in the DexGuard config. You do not need any of the settings I mentioned above. all you need is
-keepresourcexmlattributenames vector/**
Reason for this is that the AppCompat library does not look for the attributes of the vector, like viewportWidth by id, but it uses the actual atribute name. Dexguard by default strips the name, thus it never found the value. By adding the above line, you are telling DexGuard to leave the attribute names for all vector files.
I hope this saves others of much heartache.

Binary XML file line #53: Error inflating class ImageView

I build my app against
minSdkVersion 11
targetSdkVersion 23
When I run it on Samsug Galaxy S5 or Note5, the app runs fine with no problem. But when I try to run it on a Samsung S3 running android 4.4.2, it crashes with the following stack trace. I already read android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>. Does my stack trace shed some particular light so that someone can help me further?
Also the reference to line 153 in MainActivity is simply setContentView(R.layout.activity_main);
And all my themes are AppCompat such as <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
FATAL EXCEPTION: main
Process: com.business.android, PID: 24152
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.business.android/com.business.android.activities.MainActivity}: android.view.InflateException: Binary XML file line #53: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2334)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:751)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.business.android.activities.MainActivity.onCreate(MainActivity.java:153)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) 
at android.app.ActivityThread.access$900(ActivityThread.java:169) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5487) 
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:1283) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/sel_touch_feedback.xml from drawable resource ID #0x7f020081
at android.content.res.Resources.loadDrawable(Resources.java:3066)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3701)
at android.widget.ImageView.<init>(ImageView.java:127)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:855) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:751) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.business.android.activities.MainActivity.onCreate(MainActivity.java:153) 
at android.app.Activity.performCreate(Activity.java:5451) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) 
at android.app.ActivityThread.access$900(ActivityThread.java:169) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5487) 
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:1283) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:181)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:990)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
at android.content.res.Resources.loadDrawable(Resources.java:3062)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
at android.view.View.<init>(View.java:3701) 
at android.widget.ImageView.<init>(ImageView.java:127) 
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57) 
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53) 
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106) 
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980) 
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039) 
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:855) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:751) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.business.android.activities.MainActivity.onCreate(MainActivity.java:153) 
at android.app.Activity.performCreate(Activity.java:5451) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) 
at android.app.ActivityThread.access$900(ActivityThread.java:169) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5487) 
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:1283) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
at dalvik.system.NativeStart.main(Native Method) 
UPDATE
(Thanks Machinarius) Here is the drawable file that may be causing the problem. Any ideas how I might fix it?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="schemas.android.com/apk/res/android">
<item android:color="#color/colorAccentLight" android:state_selected="true"/>
<item android:color="#color/colorAccentLight" android:state_pressed="true"/>
<!--<item android:color="#color/white"></item>-->
</selector>
Thanks to comments by Machinarius and cricket_007 I was able to zero in on the problem. In the end I just removed the problem drawable, which I was creating on the fly through xml, and just used ?attr/colorControlHighlight everywhere I was using that drawable.
The drawable in question was
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="schemas.android.com/apk/res/android">
<item android:color="#color/colorAccentLight" android:state_selected="true"/>
<item android:color="#color/colorAccentLight" android:state_pressed="true"/>
<!--<item android:color="#color/white"></item>-->
</selector>
It turns out I didn't need it after all.

VectorDrawableCompat Resources$NotFoundException on KitKat and below

When I enable
vectorDrawables.useSupportLibrary = true
I get a lot of resourceNotFoundExceptions on KitKat and below devices. I get this for NavigationView for Menus and also for ImageViews with app:srcCompat
android.content.res.Resources$NotFoundException: Resource ID #0x7f02006b
at android.content.res.Resources.getValue(Resources.java:2305)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:268)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:114)
at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:206)
at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:182)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:480)
at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1053)
at android.support.v7.app.AppCompatDelegateImplV7.preparePanel(AppCompatDelegateImplV7.java:1345)
at android.support.v7.app.AppCompatDelegateImplV7.doInvalidatePanelMenu(AppCompatDelegateImplV7.java:1583)
at android.support.v7.app.AppCompatDelegateImplV7.access$100(AppCompatDelegateImplV7.java:89)
at android.support.v7.app.AppCompatDelegateImplV7$1.run(AppCompatDelegateImplV7.java:128)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:110)
for NavigationView
Process: org.ligi.gobandroid_hd, PID: 11473
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.ligi.gobandroid_hd/org.ligi.gobandroid_hd.ui.game_setup.GoSetupActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity.setContentView(GobandroidFragmentActivity.java:85)
at org.ligi.gobandroid_hd.ui.GoActivity.onCreate(GoActivity.java:108)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464) 
at android.app.ActivityThread.access$900(ActivityThread.java:172) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5653) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method) 
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:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
at org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity.setContentView(GobandroidFragmentActivity.java:85) 
at org.ligi.gobandroid_hd.ui.GoActivity.onCreate(GoActivity.java:108) 
at android.app.Activity.performCreate(Activity.java:5541) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464) 
at android.app.ActivityThread.access$900(ActivityThread.java:172) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5653) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020067
at android.content.res.Resources.getValue(Resources.java:2305)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:268)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:475)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436)
at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112)
at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:241)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:169)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:600) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
at org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity.setContentView(GobandroidFragmentActivity.java:85) 
at org.ligi.gobandroid_hd.ui.GoActivity.onCreate(GoActivity.java:108) 
at android.app.Activity.performCreate(Activity.java:5541) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464) 
at android.app.ActivityThread.access$900(ActivityThread.java:172) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:146) 
at android.app.ActivityThread.main(ActivityThread.java:5653) 
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:1291) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
at dalvik.system.NativeStart.main(Native Method) 
To support versions before Lollipop, use
com.android.support:appcompat-v7:24.0.0 (or later)
support library.
And then, instead of
ContextCompat.getDrawable(view.getContext(), id);
use this one
AppCompatResources.getDrawable(view.getContext(), id);
I found the problem: I had my vector-drawables in drawable-anydpi/ - this produces this crash - when i move the drawables to drawable/ it works fine
I was able to use the vector drawables on pre-Lollipop devices by wrapping them in a StateListDrawable (a selector).
More precisely, I created a selector drawable in XML, and then added a single vector drawable in them :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/vector_ic_action_add" />
</selector>
I then use this "wrapped" drawable in my menu. If you want more information about how it works, check out this very useful post by Chris Banes.
To fix this issue, I had to add the following code at the application startup (Application subclass) :
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
In addition to :
Use app:srcCompat in layout definition (ImageButton view in my case) instead of android:src.
Activate in gradle : vectorDrawables.useSupportLibrary = true
as far as I've read on the docs there's only XML access for ImageView.
For the Menu you'll have to use in java.
toolbar.inflateMenu(menuResId);
toolbar.getMenu()
.findItem(menuItemId)
.setIcon(VectorDrawableCompat
.createFromResource(resource, drawableId);
If you are using vectorDrawableComapt and setting it in XML remember to do it the correct way:
app:srcCompat="#drawable/ic_add"
Source:
https://android-developers.blogspot.co.uk/2016/02/android-support-library-232.html
I faced same issue but after some hour of wasting solved the issue
Remove drawables make sure just have drawable
In build.gradle use
defaultConfig {vectorDrawables.useSupportLibrary = true}
Make set vector drawable to ImageView as below
<ImageView
android:id="#+id/ivLogo"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/your_selector"
app:srcCompat="#drawable/ic_your_vector_logo" />
Your activity must extends AppCompatActiviity instead of Activity
I hope your problem solved.
For me, I was using style reference for solid color ?colorAccent for a shape. It crash on KitKat but not above. Updated to use actual color code and it goes away.
<solid android:color="#7885cb" />
One issue could be the vector itself. One of my paths was like 4k characters long and although there was a warning I just ignored it. Although it was previewing fine, it would crash at run time.

How to use SVG image in ImageView

Good Day, I have a SVG image. How can I add it to ImageView background ?
I tried to use this library But I have problem:
01-25 12:19:02.669 27719-27719/com.dvor.androidapp E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #70: Error inflating class com.caverock.androidsvg.SVGImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView(ShoppingCart.java:411)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView(ShoppingCart.java:411) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136) 
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499) 
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:5419) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NoClassDefFoundError: com.caverock.androidsvg.R$styleable
at com.caverock.androidsvg.SVGImageView.init(SVGImageView.java:80)
at com.caverock.androidsvg.SVGImageView.<init>(SVGImageView.java:66)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
at android.view.LayoutInflater.createView(LayoutInflater.java:600) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
at com.dvor.mobileapp.checkout.ShoppingCart.onCreateView(ShoppingCart.java:411) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136) 
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499) 
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456) 
at android.os.Handler.handleCallback(Handler.java:730) 
at android.os.Handler.dispatchMessage(Handler.java:92) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:5419) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) 
at dalvik.system.NativeStart.main(Native Method)
 
What I did ?
Firstly, I added dependency to gradle:
compile 'com.caverock:androidsvg:1.2.1'
Secondly, I changed ImageView to com.caverock.androidsvg.SVGImageView
<com.caverock.androidsvg.SVGImageView
android:id="#+id/recentlyViewed_imgView"
android:layout_width="100dp"
android:layout_height="100dp"
svgimageview:svg="clock.svg"
/>
After that I added xmls:svgimageview to root layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:svgimageview="http://schemas.android.com/apk/res-auto"
android:id="#+id/rowItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#272727"
android:clickable="true"
android:orientation="vertical">
This clock.svg is in the assets folder.
In new Android Studio there is possibility to import SVG to XML file, so You don't need to use external library.
In drawable right click -> New -> Vector Asset -> Local SVG file.
Then You use it normally as other drawables:
android:src="#drawable/btn_image"
On newer devices that have hardware rendering turned on by default, you need to explicitly turn on software rendering.
imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
OR add this tag in your xml
android:layerType="software"
To properly use the svgimageview:svg attribute, the app needs to know it's definition. Unfortunately, there is only a JAR version of the library at the moment, and (unlike with AARs) the needed definition does not get merged properly when the app is built.
Try copying the attrs.xml file from the library source
https://github.com/BigBadaboom/androidsvg/blob/master/androidsvg/src/main/res/values/attrs.xml
into your res/values folder.
I believe that should fix your problem.
Though SVG is XML-based Vector image, Imageview can render only XML(Vector Drawables). Thus, We need to convert SVG to XML format. We can do it using Android Vector Asset Studio.
This may be helpful to convert SVG, PSD to XML
https://medium.com/#iamitgupta1994/converting-svg-psd-to-xml-vector-drawable-using-android-vector-asset-studio-8e8ec23d5405
Right Click on Drawable -> New -> Vector Asset -> select Local file (SVG, PSD)
select Path where your image
example
/Users/yourpcname/Desktop/taka.svg
its save drawable as a xml file
Then you can use into your imageview.
Locate where your svg image is.Rightclick drawable folder on res,
choose new>>>>Vector Asset>>>Local SVG>>>> and save it as xml

Categories

Resources