Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R8 changes "protected" methods of abstract class to "public" without -allowaccessmodification flag

I have an issue with R8. In MyLib I have public abstract MyLibsClass in which I have protected methods. MyChildClass extends from MyLibsClass in MyApp and after R8's magic all protected methods (including protected abstract) in MyLibsClass are changed into public ones, and of course in MyChildClass I'm getting "attempting to assign weaker access privileges ('protected'); was 'public') issue as trying to override protected abstract methods.

Additional info

gradle-6.0.1

MyLib's build.gradle

release {
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}

proguard-rules.pro

-keep class com.example.mylib.*{
    public protected *; }

-keep class com.example.mylib.*$*{
    public protected *; }

Anyone had this kind of issue or know a way to fix this?

like image 784
Hayk Nahapetyan Avatar asked Jan 10 '20 12:01

Hayk Nahapetyan


1 Answers

So based on discussion here ,

DON'T USE DEFAULT PROGUARD SETTINGS FOR LIBRARIES

as allowAccessModification is enabled in default proguard settings, which is located in Android SDK (\Android\Sdk\tools\proguard\proguard-android-optimize.txt) and my mistake was using this for my libraries.

Citation from proguard manual

you probably shouldn't use this option when processing code that is to be used as a library, since classes and class members that weren't designed to be public in the API may become public.

So if anyone has the same issue I will suggest to create your own base config file for proguard and copy past whole default configs without "allowAccessModification" into it.

Also if someone interested more, you can track this issue. Hopefully will get separate config file for libraries in near feature.

like image 153
Hayk Nahapetyan Avatar answered Oct 01 '22 22:10

Hayk Nahapetyan