0

Using android studio AGP 7.0, Java 11 and minifyEnabled=true

following is my method

private void init(){
}

after compile this becomes public final init() due to which I am getting run time crash saying LinkageError how come access specifier is getting change after compile?

alphanso
  • 409
  • 5
  • 22

1 Answers1

1

R8 does whole program optimization, and if the method does not have a keep rule R8 can do whatever it wants with the method including changing modifiers. If you want to make sure the method stays you can add a keep rule like this:

-keep class <class name holding method> {
  private void init();
}

then the method should not be touched by R8.

Is the LinkageError caused by adding code at runtime which is not processed by R8? For whole program optimization and boundaries to code not known to R8 must be covered by a keep rule.

sgjesse
  • 3,793
  • 14
  • 17