NullPointer when minifyEnabled is set to true

Viewed 170

I have an issue with my app when minifyEnabled is set to true in my build.gradle

The items in the RecyclerView are shown without any property (so no description, no other stuff, it's like an empty object is added to RecyclerView) in it and when it try to make any action on some of items in that RecyclerView i get a NullPointer (while if minifyEnabled is set to false all works as it have to)

One of points where the app crashes is the following at the line with equals:

public Menu.Prodotti getItem(Menu.Prodotti prodotto) {
    for (Menu.Prodotti item : items) {
        if (item.codice.equals(prodotto.codice) && item.jump == prodotto.jump) {
            return item;
        }
    }
    return null;
}

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object referenc

It seems like Menu.Prodotti is minified and it's can't be load.

But in my proguard-rules i've added the whole Menu class to be ignored from minifizing, what else should i try to do?

Here is my proguard-rules.pro

-keep class it.gabtamagnini.visualposmobile.models.Menu
-keepclassmembers class it.gabtamagnini.visualposmobile.models.Menu { *; }
1 Answers

That was easier than i tought i had to include the inner classes by adding $* to -keep class

So my proguard-rules.pro looks like this now and all is working as it have to:

-keep class it.gabtamagnini.visualposmobile.models.Menu$* { *; }
-keepclassmembers class it.gabtamagnini.visualposmobile.models.Menu { *; }
Related