How can I track down the cause of Android "found an invalid color" error
Asked Answered
G

5

22

During build of my android application I am getting the following error:

:app:mergeDev_testingDebugResources
error: found an invalid color.

I don't get any line of code or even which file it is having a problem with. I have a large number of outstanding changes (stupid me) which I don't want to roll back - but I'm totally stumped as to how to work out what is wrong.

Gaskin answered 28/11, 2017 at 23:49 Comment(0)
G
55

For future reference - this error is what you get if you have added an image as a 9-pack and it isn't yet properly formatted with the black pixel borders. The error message could be far more helpful, i.e. actually saying which file the error occurs with would be nice, but the solution is just to go through all your 9 pack files in Android Studio and open then save each of them.

Gaskin answered 29/11, 2017 at 0:48 Comment(9)
You can add Gradle stacktraces. #21674591Duvetyn
I opened each of my 9 pack files in Android Studio, saved them...but still get the error. What am I doing wrong?Necessitous
@Necessitous I'd try open all of the 9 packs in an external image editor and verify that all the pixels in the 1 pixel border around the image are completely transparent.Gaskin
that's it, and still is this way in android studio 3 with gradle 3.1.Serenity
@mrezash I'm not surprised :-)Gaskin
I had to put a white pixel border, black didn't work and neither transparent!Epigene
@mikeaxle that's strange, I'm pretty sure mine are transparent. Well, as long as it works...Gaskin
hey @Gaskin i'm having the same issue. can you tell us how did you fix the image to make the border transparent? :) #53559770Fancywork
@Fancywork I literally just double-click the 9 pack file in Android Studio to open it, then saved it. Android Studio auto-fixed it by surrounding it with a transparent 1px border.Gaskin
O
1

First of all, check your layout directory in file explorer bcoz when you have made changes in the main layout file then you could have changed respective example: v-21 or v-13 layout file too. This error occurs when you apply some element property which is not supported by previous versions like v-21.

I hope I have given detail about this, if any explanations are needed plz let me know.

Osteomyelitis answered 24/11, 2018 at 6:46 Comment(0)
P
0

Yes, the problem is in 9-path image. At least in my case. The problem was in black lines in the borders of image. It should be only black and transparent. Nothing else. In my case there was shadow from view with alpha. With photoshop I remove any color pixels of borders (except black lines)

Phenanthrene answered 28/2, 2019 at 14:36 Comment(0)
W
0

At Android Studio launch Analyze -> Inspect code. Then resolve all errors

Widespread answered 24/6, 2019 at 10:9 Comment(0)
C
0

In my case , i have done mistake while writing color, like -

<color name="mainBackground">#8e00ed></color>

then look i have added extra symbol this-">" after my color , it should only be

<color name="mainBackground">#8e00ed</color

Then it worked fine for me. Just check between two symbols "only color code" should come "no extra symbols,no apostophies,no semicolons" should be there.

Thank You!!!

Consultant answered 29/11, 2020 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.