'Proguard / R8 rule to keep package-private class members

For compiling an .aar library in an Android Java project I need to protect a static package-private method of a class to be protected from removal by R8:

public final class MyClass {
...
    static void myStaticMethod(...){
    ...
    }
...
}

I tried a Proguard / R8 Rule like this:

-keep class * {
    public protected *;
}

but it did not work, the method gets eleminated. Is there a special keyword for package-private methods?

Of course the workaround to mark the method with a @Keep annotation did work, but that leaves me with the task to find all package-private methods manually.



Solution 1:[1]

In the end RTFM was the solution :) Reading the "Class Specifications" section of the proguard manual gave me the right idea:

-keep class * {
    !private *;
}

This keeps everything that has no private attribute which is a precise enough selection in my case.

Solution 2:[2]

Finally I had to address the input child element beneath the ion-input, using a simple method:

callInputChild(){
        this.inputType = this.inputType === 'password' ? 'text' : 'password';
        document.querySelector("#killswitch > input").setAttribute('type', this.inputType)
        console.log(this.inputType)
    }

then in the HTML:

<ion-input id="killswitch"></ion-input>
<button (click)="callInputChild()" style="background: white !important;" item-right icon-only>
<ion-icon *ngIf="inputType === 'password'" item-right name="eye"></ion-icon>
<ion-icon *ngIf="inputType === 'text'" item-right  name="eye-off"></ion-icon>
</button>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nantoka
Solution 2 J. Lobo