New gradle plugin version (4.1.0): no longer returning any ressource fields

Viewed 307

To get all drawables in an android app (using Kotlin) I call R.drawable::class.java.fields.
Since yesterday it worked perfectly fine but as I updated

classpath "com.android.tools.build:gradle:4.0.2"  

to

classpath "com.android.tools.build:gradle:4.1.0"

it just returns an empty array (so no fields / drawables are found).


I changed anything other than this and also tried to clean the project, rebuild it, invalidate android studio caches and to downgrade and upgrade again, but nothing worked for me.


Why is that and is there a way to fix that weird bug?

1 Answers

I found a solution:

I made it working by explicitly exluding the fields out of resource shrinking by adding an entry to the proguard rules as explained here: https://github.com/mikepenz/AboutLibraries/issues/331

You just have to add the following to the proguard-rules.pro file for your app module:

-keep class **.R$* {
    <fields>;
}
Related