问题描述
我第一次尝试使用具有混淆和代码优化功能的R8的Android Studio版本.
Contenuti
是 manifest.xml
中提到的活动.
mostraView
和 nascondiView
是我创建的方法,它们不在任何库中,也不扩展任何内容,因此我希望看到它们的名称已更改.
void mostraView(View v){v.setVisibility(View.VISIBLE);}无效的nascondiView(View v){v.setVisibility(View.GONE);}
此R8的行为正确吗?
如何设置R8来混淆它们,或者至少混淆这两个?
非常感谢!
此默认规则可能是导致此问题的原因:
#我们希望将可以在XML属性onClick中使用的方法保留在Activity中.-keepclassmembers类*扩展了android.app.Activity {公共无效*(android.view.View);}
我是通过使用诊断开关 -printseeds
和 printconfiguration
来获得的.
匹配的方法将是(a)在扩展Activity的类中定义的,并且(b)具有与模式匹配的方法签名(基本上是任何名称和View参数).
但是,唯一可以重现您问题的方法是,如果我修改了访问修饰符,使其包含 public
,如下所示:
public void mostraView(View v){v.setVisibility(View.VISIBLE);}
请注意添加了关键字 public
.因此,假设您所发布的代码是逐字记录的,那么默认访问修饰符就是不匹配该模式的package friend.
无论如何,我都可以进行-经过重述的修改可以重现该问题,并提供了基于默认-keeps的可能解释.
请注意,保留"一词已被重载,因为它也适用于混淆.
I'm trying for my first time an Android Studio version with R8 that perform obfuscation and code optimization.
As the official documentation says:
I think that R8 will rename all method and class names, but if I analyze the APK through "Build -> Analyze APK..." I can read most of the original method and class names.
Contenuti
is an Activity mentioned in the manifest.xml
.
mostraView
and nascondiView
are methods created by me, they aren't in any library, they don't extend nothing, so I expected to see their name changed.
void mostraView(View v)
{
v.setVisibility(View.VISIBLE);
}
void nascondiView(View v)
{
v.setVisibility(View.GONE);
}
Is this R8's behavior correct?
How to set R8 to obfuscate all of them, or at least these two?
Thanks a lot!
This default rule may be the cause:
# We want to keep methods in Activity that could be used in the XML attribute onClick.
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
I obtained this from using diagnostic switches -printseeds
and -printconfiguration
.
A matched method would be (a) defined in a class extending Activity and (b) have a method signature matching the pattern (essentially any name and a View paramter).
However the only way I could reproduce your issue is if I modified the access modifier to include public
as in:
public void mostraView(View v)
{
v.setVisibility(View.VISIBLE);
}
Note the addition of the keyword public
. So assuming your posted code is verbatim then the default access modifier is package friend which would not match the pattern.
Anyways that's as far as I can take - was able to reproduce the problem with noted modification and provided a possible explanation based on default -keeps.
Note the term "keep" is overloaded in that it also applies to obfuscation.
这篇关于为什么R8不重命名所有方法和类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!