Open gregkorossy opened 7 years ago
Thanks @Gericop for the detailed issue. Can you also print the relevant error message output from logcat?
Sure, here you go: error_log.txt
The most important part is this:
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
at android.content.res.Resources.loadDrawable(Resources.java:1995)
... 83 more
It's pretty easy to find the problem: the GenericDraweeHierarchyInflater
class' getDrawable(...)
method uses context.getResources()
to inflate the drawable. However, this cannot be used on pre-lollipop devices to inflate vector drawables, that task requires AppCompatResources.getDrawable(...)
.
AppCompatResources
since the whole library would have to depend on AppCompatResources
otherwise. Another solution would be to extend SimpleDraweeView
and inflate the placeholder manually using AppCompatResources
.I think there are two options to solve this:
ImagePipelineConfig.Builder
similar to setPlatformBitmapFactory(...)
.Extending SimpleDraweeView
would only solve the problem if custom attributes were introduced for all of the image types because the default placeholderImage
(and other image setter) attribute gets resolved before anything else due to the super call, which would result in the same exception. Custom attributes might also mean that the *ScaleType
attributes would need to be parsed too for the custom attributes.
@Gericop
I don't have such issues and can use vector drawables in XML in placeholderImage
and there are no crashes on APIs down to 16 (min version in the actual production app).
You might have a problem because of vectorDrawables.useSupportLibrary = true
property in your Gradle file according to this StackOverflow thread.
@vbuberen Do you use AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
instead? Because that is still a no-no for the memory issues it might introduce (see the documentation).
Nope, I don'. As you might know, for devices with API lower than 21 PNGs are generated instead of vectors automatically - on some really old devices with small resolution screen you can see that some drawables aren`t clear-cut like vector drawables should be. But still everything works fine with Fresco and placeholders.
@vbuberen Well, I've always had vectorDrawables.useSupportLibrary = true
in my build.gradle, yet it crashes on < API 21 devices.
@Gericop Kind of strange. Have you tried to check everything again without DataBinding
? And what happens if you remove vectorDrawables.useSupportLibrary = true
?
@oprisnik I was able to fix this issue by adding AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
in the onCreate of Application class. and this automatically fixes fresco:placeholderImage="@drawable/vector_graphic"
I have tested this in API level 19.
A similar question is posted on stackoverflow
This should also be added on official documentation FAQ's section.
@ibtisamasif The problem with that call is clearly documented:
This feature defaults to disabled, since enabling it can cause issues with memory usage, and problems updating Configuration instances. If you update the configuration manually, then you probably do not want to enable this. You have been warned.
Description
I have a
SimpleDraweeView
and a vector drawable XML. I tried to use the said XML as a placeholder in the Drawee but on API 17 (so probably below API 21) could not inflate the view and crashed the app.AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
does not seem to be a viable option asReproduction
Define the layout XML for the Drawee:
where
@drawable/ic_image_white_24dp
isic_image_white_24dp.xml
:Note that the
SimpleDraweeView
has anapp:imageUri
attribute this is here because the data binding would not work otherwise, the implementation is pretty simple (it is not relevant to the bug though):The layout gets inflated by
DataBindingUtil
from aRecyclerView.Adapter
located in a (support)Fragment
that is attached to the parentAppCompatActivity
.The gradle file contains the necessary line for supporting vector drawables on lower API levels:
Additional Information