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.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user3690202
  • 3,844
  • 3
  • 22
  • 36

5 Answers5

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.

user3690202
  • 3,844
  • 3
  • 22
  • 36
  • You can add Gradle stacktraces. https://stackoverflow.com/questions/21674091/how-to-add-stacktrace-or-debug-option-when-building-android-studio-project – OneCricketeer Nov 29 '17 at 00:55
  • I opened each of my 9 pack files in Android Studio, saved them...but still get the error. What am I doing wrong? – wooldridgetm Apr 13 '18 at 21:49
  • 2
    @wooldridgetm 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. – user3690202 Apr 19 '18 at 00:21
  • that's it, and still is this way in android studio 3 with gradle 3.1. – mamzi Jun 14 '18 at 22:17
  • @mrezash I'm not surprised :-) – user3690202 Jun 14 '18 at 22:19
  • 1
    I had to put a white pixel border, black didn't work and neither transparent! – Mike Axle Sep 17 '18 at 11:40
  • @mikeaxle that's strange, I'm pretty sure mine are transparent. Well, as long as it works... – user3690202 Sep 21 '18 at 19:55
  • hey @user3690202 i'm having the same issue. can you tell us how did you fix the image to make the border transparent? :) https://stackoverflow.com/questions/53559270/invalid-color-in-android-compilation-how-to-fix-9-png – chris Nov 30 '18 at 14:28
  • @chris 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. – user3690202 Dec 02 '18 at 03:28
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.

amit pandya
  • 1,384
  • 13
  • 22
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)

Eugene Voronoy
  • 1,384
  • 1
  • 14
  • 18
0

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

Evgenii Vorobei
  • 1,457
  • 18
  • 20
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!!!

Dharman
  • 30,962
  • 25
  • 85
  • 135