question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vector drawable does not work as placeholder image on API 17 (and probably below API 21)

See original GitHub issue

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 as

This feature defaults to disabled, since enabling it can cause issues with memory usage, and problems updating Configuration instances.

Reproduction

Define the layout XML for the Drawee:

 <com.facebook.drawee.view.SimpleDraweeView
	android:id="@+id/cover"
	android:layout_width="60dp"
	android:layout_height="87dp"
	android:layout_marginEnd="12dp"
	android:layout_marginRight="12dp"
	app:imageUri="@{item.cover}"
	fresco:actualImageScaleType="centerCrop"
	fresco:placeholderImage="@drawable/ic_image_white_24dp"
	fresco:placeholderImageScaleType="centerInside"/>

where @drawable/ic_image_white_24dp is ic_image_white_24dp.xml:

<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="#FFFFFFFF"
        android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
</vector>

Note that the SimpleDraweeView has an app: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):

@BindingAdapter({"imageUri"})
public static void loadImage(SimpleDraweeView view, Uri imageUrl) {
    view.setImageURI(imageUrl);
}

The layout gets inflated by DataBindingUtil from a RecyclerView.Adapter located in a (support) Fragment that is attached to the parent AppCompatActivity.

The gradle file contains the necessary line for supporting vector drawables on lower API levels:

android {
    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
}

Additional Information

  • Fresco version: 1.3.0
  • Platform version: API 17, HTC One X
  • Support lib version: 25.3.1

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ibtisamasifcommented, Nov 22, 2017

@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.

0reactions
Gericopcommented, Nov 22, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use VectorDrawables in Android API lower than 21?
Once you have a vectorDrawable image in your res/drawable, the Gradle plugin will automatically generate raster PNG images for API level 20 and ......
Read more >
How to handle vector drawables on Android devices with API ...
As you know using VectorDrawable is possible on devices with API at least 21 (Lollipop). But fortunately it turned out that AndroidX ...
Read more >
Vector drawables overview | Android Developers
A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated...
Read more >
User talk:Chieftain Alex/Archive 14 - Guild Wars 2 Wiki (GW2W)
25.1 Possibly related: equipment prefixes; 25.2 "when lye turns the API back on ... Whole lotta nothing on the other two, though Rodgort's...
Read more >
splash screen size android app - Cutacut.com
The best way to deal with this problem is to create 3 splash screens. ... caught my eye here is the introduction of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found