References to other resources are not supported by

2019-01-21 01:13发布

AndroidStudio 3.0 / Android Gradle plugin 3.0

<vector>
  <path android:fillColor="@color/image_button_disabled"/>
</vector>

I get this error:

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

Will it be possible to resolve it or is it a deprecated solution?

7条回答
小情绪 Triste *
2楼-- · 2019-01-21 02:05

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

<vector
  <path
    android:fillColor="#FFF"/></vector>
查看更多
狗以群分
3楼-- · 2019-01-21 02:05

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

查看更多
戒情不戒烟
4楼-- · 2019-01-21 02:07

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

查看更多
看我几分像从前
5楼-- · 2019-01-21 02:09

In your app build.gradle add the following line:

defaultConfig{
   vectorDrawables.useSupportLibrary = true
}

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

查看更多
Viruses.
6楼-- · 2019-01-21 02:10

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'
}
查看更多
家丑人穷心不美
7楼-- · 2019-01-21 02:10

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"

查看更多
登录 后发表回答