为什么ProGuard的保持onCreate()方法? [英] Why does ProGuard keep the onCreate() method?

查看:345
本文介绍了为什么ProGuard的保持onCreate()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想换我解决这个头,但我只是不明白为什么这种情况正在发生:按照默认proguard.cfg文件中,我定义了以下规则:

I'm trying to wrap my head around this, but I simply don't understand why this is happening: As per the default proguard.cfg file, I define the following rule:

-keep public class * extends android.app.Activity

据我了解,这意味着:保留任何活动类作为一个切入点,但随时缩小/模糊/优化它里面的任何东西(否则我' d必须使用如<方法> 通配符preserve方法也一样,右)

as far as I understand, this means: keep any Activity class as an entry point, but feel free to shrink/obfuscate/optimize anything inside it (otherwise I'd have to use e.g. the <methods> wildcard to preserve methods, too, right?).

现在我的测试活动是这样的:

Now my test Activity looks like this:

public class MyActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        ...
    }

    public void unusedMethod() {
    }
}

如果我现在导出签署APK,和ProGuard的被调用时,它会删除 unusedMethod 如预期,但将保持的onCreate 方法,而不是混淆它的名字。这是为什么?

If I now export a signed APK, and ProGuard is invoked, it will remove unusedMethod as expected, but it will keep the onCreate method and not obfuscate its name. Why is that?

推荐答案

您的configuuration选项的理解是正确的。不过,ProGuard的不能删除或重命名的onCreate 方法,因为它覆盖android.app.Activity onCreate方法。重新命名它会破坏应用程序。不重写库的方法,如 unusedMethod ,方法可以安全地取出,内联,或者至少重新命名。

Your understanding of the configuuration options is correct. However, ProGuard can't remove or rename your onCreate method, because it overrides the onCreate method in android.app.Activity. Renaming it would break the application. Methods that don't override library methods, like unusedMethod, can safely be removed, inlined, or at least renamed.

该方法 M 应该改名,除非你是为它指定一些-keep选项。您可以检查该选件 -whyareyoukeeping

The method M should be renamed, unless you are specifying some -keep option for it. You can check that with the option -whyareyoukeeping.

这篇关于为什么ProGuard的保持onCreate()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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