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

谁都会走 提交于 2020-05-15 11:47:06

问题


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?


回答1:


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.




回答2:


This was also reported on the R8 bug tracker, and resolved there. See http://issuetracker.google.com/147447502.



来源:https://stackoverflow.com/questions/59681793/r8-changes-protected-methods-of-abstract-class-to-public-without-allowacces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!