References to other resources are not supported by build-time PNG generation

被刻印的时光 ゝ 提交于 2019-11-28 15:33:17
mwa91

In your app build.gradle add the following line:

defaultConfig{
   vectorDrawables.useSupportLibrary = true
}

See Android Developers: Vector Drawables Backward Compatibility Solution for details.

you need to use the hex code directly not referring to a resource.

<vector
  <path
    android:fillColor="#FFF"/></vector>

Little bit more context for this error:

  • Android 5.0 (API level 21) was the first version to officially support vector drawables.
  • If you use minSdkVersion lower than 20, there are two solutions for vector drawable
    • Android Studio's Vector Asset Studio generate PNG. Please take a look Android Studio document. But, references to other resources are not supported by build-time PNG generation.
    • Use support library
  • Or, use 21 or above for minSdkVersion

For support library, add a statement to your build.gradle file:

android {
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
}

dependencies {
  compile 'com.android.support:appcompat-v7:23.2.0'
}

If your minSdkVersion is 21 you can disable the generation of PNG by adding this line:

// set to an empty list to disable the feature
vectorDrawables.generatedDensities = [] 

Removing this line will still generate the PNGs.

Source: http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.VectorDrawablesOptions.html

Do not use colorReference at fillColor attribute in Vector drawable just use hexa code

use like this

<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="#1abc9c"
    android:pathData="M9,11L7,11v2h2v-2zM13,11h-2v2h2v-2zM17,11h-2v2h2v-2zM19,4h-1L18,2h-2v2L8,4L8,2L6,2v2L5,4c-1.11,0 -1.99,0.9 -1.99,2L3,20c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.9,-2 -2,-2zM19,20L5,20L5,9h14v11z"/>

instead of this

<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="@color/colorPrimary"
    android:pathData="M9,11L7,11v2h2v-2zM13,11h-2v2h2v-2zM17,11h-2v2h2v-2zM19,4h-1L18,2h-2v2L8,4L8,2L6,2v2L5,4c-1.11,0 -1.99,0.9 -1.99,2L3,20c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.9,-2 -2,-2zM19,20L5,20L5,9h14v11z"/>

I've been able to work around this by doing the following:

  1. create a drawable-v21 folder and copy all your drawable xmls that use variables there
  2. in the original drawable folder change all the icons to use a static color

This way the compiler will work

I think you are using android:fillColor="@color/image_button_disabled" this code for vector drawable.

// image_button_disabled.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/circular_image_color_pressed" android:state_pressed="true" />
    <item android:color="@color/circular_image_color_normal" />
</selector>

It's not supported.

Just replace it with android:fillColor="#c4ca5e"

To add up to @mwa91 answer.

In case you need dynamic theming of drawable, but you don't have time to update your layouts and go with @mwa91 answer and change all android:src="@drawable/..." attributes to app:srcCompat="@drawable/...", you can always use hex color value in drawable and then later tint the drawable in ImageView:

<ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/your_drawable"
      android:tint="@color/image_button_disabled"
      />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!