Android Release error: Expected a color resource id (R.color.) but received an RGB integer
Asked Answered
M

3

7

I have an application in the market for a year. Last week, I have changed the source code of my app. When I wanted to build the release version Android Studio throws an Error:

"Error: Expected a color resource id (R.color.) but received an RGB integer [ResourceType]"

Color is only used in this part of code and I haven't made ​​any changes in this part:

if (android.os.Build.VERSION.SDK_INT >= 16) {
            rlFlash.setBackground(new ColorDrawable
                    (Color.parseColor(("#86cc55"))));
        }
        else{
            rlFlash.setBackgroundDrawable(new ColorDrawable
                    (Color.parseColor(("#86cc55"))));
        }

It is so strange that in the Debug version Android studio didn't throw any error and I can build the apk.

Do you know whats happen??

Thanks.

Myron answered 20/4, 2016 at 20:3 Comment(0)
E
5

Do it like this:

rlFlash.setBackgroundColor(Color.parseColor("#86cc55"));
Eudoca answered 21/4, 2016 at 3:13 Comment(0)
G
4

Though it's too late, but this answer is for those who may still get this error while taking release build like me. Don't know if it's a solution or just workaround.

@SuppressLint("ResourceType")

Use this at your method signature like below where you get the error.

@SuppressLint("ResourceType")
public void aMethodWhereYouMayGetTheError(){
}

By using this you will be able to take release build without that error.

Guyenne answered 6/6, 2018 at 4:30 Comment(0)
P
1

If you have used the anotation @ColorRes in this method then remove that. The apk will be generated successfully. Refer to SO Answer to clarify further about the lint checks. The answer is quoted below:

There are Java annotations to support these checks in your own code. They can all be found in the android.support.annotations package: IdRes DrawableRes LayoutRes StringRes ColorRes &c In this case, for example, I could use:

private void mySetContentView(@LayoutRes int resourceId) {
    setContentView(resourceId); 
} 

and Android Studio will check that the provided resource id is indeed for a layout. Moreover, these annotations are exported, so they can be especially useful when designing a library.

Pompon answered 6/12, 2016 at 12:25 Comment(1)
Link-only answers are highly discouraged here because the links may become dead in the future. I suggest you edit your answer with quotes from the sources you cite.Machute

© 2022 - 2024 — McMap. All rights reserved.