VectorDrawableCompat Resources$NotFoundException on KitKat and below
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
Resource not found exception for vectordrawables
- Check vector drawable
<path>
. Sometimes this happens when<path>
tag in XML file is too long. - Try to move your image from
drawable
todrawable-nodpi
.
UPDATE
- Try to use AppCompatResources.getDrawable(view.getContext(), id); when getting drawable
VectorDrawable Resources$NotFoundException while xml vector drawable resource file does exist
When I was applying patch for gradient sections I noticed that AndroidStudio highlighted these gradient sections saying that it is supported from API 24 and my project min API is 21. So I have decided to check other warnings like:
Very long vector path (1456 characters), which is bad for performance.
Considering reducing precision, removing minor details or rasterizing
vector.
So I've started suspecting it as an issue source because there was an error message (red colored text) given in build window of AndroidStudio stating:
string too large to encode using UTF-8 written instead as
'STRING_TOO_LARGE'.
But there is no glue or pointing to source of this problem, its just states that I have a very long String somewhere in my project, so it could be preshipped realm database file for instance or something like.
Finally I found an anomaly in one of my vector drawables - it was a path string containing about 51k chars! Of course no warning was given to me at importing time (svg to xml, done using AndroidStudio).
Removing this path solved the crash issue but also a part of an image was lost.
So I've degrouped a problematic path group using Sketch and after importing it resulted in 2 paths of 19k and 24k chars, which is not good either, but it works now without any crash.
btw I am unable to find any information on string length limitations for vector/xml but gradle does apply this limitation at build time, so its known.
The limit of one xml string length revealed in this SO question and there is no official document on that could be found.
Android Resources$NotFoundException Crash Report
Solved! I just moved the XML drawables to the drawable/ folder. Works like magic. Thanks to @ligi.
VectorDrawableCompat Resources$NotFoundException on KitKat and below
Error inflating class ImageButton (Android KitKat)
The problem is you are using android:background
here with android:srcCompat
it will work . To make it work with android:background
below API 21 you can have a layer-list
and and add the vector inside layer-list
.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_polis_produk"/>
</layer-list>
and then set it to ImageButton
background.
On other hand i don't use ImageButton
very often i think you can just replace it with ImageView
and use android:srcCompat
it will work and it much easier.
Related Topics
Disable The Swipe Gesture That Opens The Navigation Drawer in Android
Coordinator Layout with Toolbar in Fragments or Activity
Permission Denial: Not Allowed to Send Broadcast in Android
Eclipse Indexer Errors When Using Stl with Android Ndk
Web App on Android Browser Width Issue
Equivalent of Listview.Setemptyview in Recyclerview
How to Read All The Coming Notifications in Android
HTML5 <Video> Element on Android Does Not Play
Android, Asynctask, Check Status
How to Create a Looper Thread, Then Send It a Message Immediately
Opening a File from Assets Folder in Android
Why Does Calling Getwidth() on a View in Onresume() Return 0
Android: Using HTML5 to Determine Geolocation in Webview with JavaScript API
Extract Notification Text from Parcelable, Contentview or Contentintent
Is Fcm (Firebase Cloud Messaging) Token for One Device or for One Account
How to Integrate Opencv 4.0 into a Pure C++ Android Ndk Project