问题描述
我有 R8 的问题.在 MyLib
中,我有公共抽象 MyLibsClass
,其中我有保护方法.MyChildClass
从 MyApp
中的 MyLibsClass
扩展而来,在 R8 的魔法之后,MyLibsClass
中的所有受保护的方法(包括受保护的抽象)都被改变了进入公共的,当然在 MyChildClass
我得到 试图分配较弱的访问权限(受保护");是 'public')
问题,因为试图覆盖受保护的抽象方法.
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.
附加信息
gradle-6.0.1
MyLib 的 build.gradle
MyLib's build.gradle
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}
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?
推荐答案
所以基于讨论这里
在处理要执行的代码时,您可能不应该使用此选项被用作库,因为类和类成员不是在 API 中设计为公开的可能会公开.
因此,如果有人遇到同样的问题,我会建议为 proguard
创建您自己的基本配置文件,并将没有 "allowAccessModification"
的整个默认配置复制到其中.
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.
这篇关于R8 更改“受保护"抽象类的方法“公共"没有 -allowaccessmodification 标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!