R8改变了“受保护"的状态.抽象类“公开"的方法.没有-allowaccessmodification标志 [英] R8 changes "protected" methods of abstract class to "public" without -allowaccessmodification flag

查看:235
本文介绍了R8改变了“受保护"的状态.抽象类“公开"的方法.没有-allowaccessmodification标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R8有问题.在MyLib中,我具有受保护的方法的公共摘要MyLibsClass. MyChildClassMyApp中的MyLibsClass扩展,并且在R8的魔力作用下,MyLibsClass中的所有受保护的方法(包括受保护的抽象)都被更改为公共方法,并且在MyChildClass中,我当然收到了"attempting to assign weaker access privileges ('protected'); was '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.

其他信息

6.0.1级

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?

推荐答案

因此,根据讨论在此处

请勿为图书馆使用默认程序设置

DON'T USE DEFAULT PROGUARD SETTINGS FOR LIBRARIES

在默认的Proguard设置中启用了

as allowAccessModification,该设置位于Android SDK (\Android\Sdk\tools\proguard\proguard-android-optimize.txt) 中,我的错误是将其用于我的库.

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.

proguard手册

在处理要处理的代码时,您可能不应该使用此选项 用作库,因为没有的类和类成员 旨在在API中公开的设计可能会公开.

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.

因此,如果有人遇到相同的问题,我建议为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标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆