Shubham Sharma
Shubham Sharma

Reputation: 98

Invalid color value ?android:colorControlNormal

I have a drawable resource file like this:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
    <path
        android:fillColor="?android:colorControlNormal"
        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"
        tools:targetApi="lollipop" />
</vector>

On Gradle Build, Error is as follows:

Invalid color value ?android:colorControlNormal
at com.android.ide.common.resources.MergedResourceWriter$FileGenerationWorkAction.run

What I tried: I changed it to ?attr/colorControlNormal, but still same error I am stuck at this. Can somebody help?

Upvotes: 2

Views: 2818

Answers (2)

Shubham Sharma
Shubham Sharma

Reputation: 98

If you have updated the Gradle Plugin to the latest version, restore it to 3.6.1 as It seems this is working till version '3.6.1'.

Upvotes: 0

Stoyan Milev
Stoyan Milev

Reputation: 735

?attr/colorControlNormal works for me. As I could see from your code you have tools:targetApi="lollipop" which means your minSdk is lower than API 21. Vector drawables are supported down to API 21. Before that Gradle generates PNGs for that vector drawables. By using theme attributes like ?attr/colorControlNormal means your drawable color could vary depending on the theme of its context. Therefore gradle could not generate PNGs for it as it doesn't know about the context.

The solution for this is either update the minSdk version to be atleast 21 or use a static color or static color reference. For example: android:fillColor="@color/someColor or android:fillColor="#FF00FF00"

Upvotes: 3

Related Questions