我从Google Material.io下载了一个图标。在集成后尝试构建我的项目时,遇到了以下错误:Can't process attribute android:fillColor="@android:color/white"
这是一张截图:
我从Google Material.io下载了一个图标。在集成后尝试构建我的项目时,遇到了以下错误:Can't process attribute android:fillColor="@android:color/white"
这是一张截图:
android
部分中添加以下行:defaultConfig{
vectorDrawables.useSupportLibrary = true
}
查看此处以获取更多详细信息:矢量图形总览
com.android.application
模块中工作,但无法在 com.android.library
模块中工作。 - StuStirlingapp:srcCompat
而不是android:src
属性来引用矢量图形。 - Jimmy_Rw打开您下载的可绘制对象,将 android:fillColor="@android:color/white"
替换为 android:fillColor="#ffffff"
。 在矢量图中,必须明确设置 fillColor
属性,而不能引用其他资源。
有两种修复方法。
一种快速的选项是转到问题所在的XML文件,将 android:fillColor="@android:color/white"
更改为 android:fillColor="#FFFFFF"
。错误会立即消失。但是,如果您将来有任何其他带有类似行的文件,此问题仍将再次发生。
以下是永久解决方案:
转到您的 build.gradle 文件并添加以下内容:
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
同步一下,错误会立即消失。
您应该使用AppCompatTheme来访问?attr/colorControlNormal
AS 3.3.2 / gradle-4.10.1
我遇到了同样的编译器问题:
Error: java.lang.RuntimeException: java.lang.RuntimeException: Error while processing .../main/res/drawable/ic_white_set.xml : Can't process attribute android:fillColor="@color/selector_tab_color": references to other resources are not supported by build-time PNG generation.
我打开了被指控的文件,并得到了以下 Lint 警告:
Resource references will not work correctly in images generated for this vector icon for API < 21; check generated icon to make sure it looks acceptable.
Inspection info:Vector icons require API 21 or API 24 depending on used features, but when minSdkVersion is less than 21 or 24 and Android Gradle plugin 1.4 or higher is used, a vector drawable placed in the drawable folder is automatically moved to drawable-anydpi-v21 or drawable-anydpi-v24 and bitmap images are generated for different screen resolutions for backwards compatibility. However, there are some limitations to this raster image generation, and this lint check flags elements and attributes that are not fully supported. You should manually check whether the generated output is acceptable for those older devices. Issue id: VectorRaster
接着我检查了我的 build.gradle
文件,果然它们都将 minSdkVersion
设置为16。
所以,作为 @Bhavesh Moradiya 解决方案的替代方法,我将 minSdkVersion
设置为21,问题得到了解决。
缺点是您将失去对SDK < 16的设备的支持。