Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid using Resource IDs in const fields - AGP 8.0

I've been getting this warning recently: enter image description here

Resource IDs will be non-final by default in Android Gradle Plugin version 8.0, avoid using them in const fields

This applies mostly to custom views, where I have declared drawables or colors that might be needed.

What would be the alternative for declaring these fields?

like image 964
Wrakor Avatar asked May 28 '26 21:05

Wrakor


1 Answers

When I upgraded to Android Gradle 8.0, it added this line automatically to my gradle.properties file:

android.nonFinalResIds=false

Which disables the feature and doesn't require any "migration" logic (the const vals don't have to be changed).

If you want to enable this flag, you'd have to remove the const modifier from all the variables that have a resource assigned to them.

like image 63
Wrakor Avatar answered May 30 '26 09:05

Wrakor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!