Android的Proguard的不内联 [英] Android Proguard does not inline

查看:1249
本文介绍了Android的Proguard的不内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的Andr​​oid SDK(4.1),我尝试导出一个签名罐Proguard的启用。然而,反编译优化APK之后,我发现,我没有料想到会被内联方法则没有。

I am using the latest Android SDK (4.1) and I tried exporting a signed jar with Proguard enabled. However, after decompiling the optimized APK, I noticed that methods that I would have expected to be inlined were not.

我知道Proguard的跑,因为code的正常进行模糊处理。因此,为了证实这一点,我添加了这个方法,我的活动:

I know that Proguard ran because the code was correctly obfuscated. So to confirm this, I added this method to my Activity:

private void testInlining()
{
    mConfig = null;
}

这私有方法只调用一次在我的活动,因为它是私有的,它应该是很明显的,这被称为一次优化,它应该被内联。

This private method is called only once in my activity, and because it is private, it should be very obvious to the optimizer that it is called only once and that it should be inlined.

该文件说,所有的优化默认情况下启用,并且Proguard的这是短期或只调用一次联方法。

The documentation says that all optimizations are enabled by default, and that Proguard "Inline methods that are short or only called once".

是否有特定的标志,我应该给ProGuard的,以使内联?

Is there a specific flag I should give to Proguard to enable inlining?

修改

EDIT

我ProGuard的配置文件包含

My proguard configuration file contains

-optimizationpasses 5
-allowaccessmodification
-overloadaggressively
-repackageclasses ''
-dontskipnonpubliclibraryclasses

修改

EDIT

使用后

-whyareyoukeeping class com.templatecompany.templateappname.EntryPointActivity {*;}

我明白为什么该方法不内联的原因:

I get the reason why the method is not inlined:

 [proguard] com.templatecompany.templateappname.EntryPointActivity: void testInlining() (20:21)
 [proguard]   is invoked by    com.templatecompany.templateappname.EntryPointActivity: com.td.media.ivConnection.IvConfig getIvConfig() (14:15)
 [proguard]   implements       com.td.widget.MainActivity: com.td.media.ivConnection.IvConfig getIvConfig()
 [proguard]   is invoked by    com.td.widget.MainActivity: void onCreate(android.os.Bundle) (140:175)
 [proguard]   implements       android.app.Activity: void onCreate(android.os.Bundle)
 [proguard]   is a library method.

但我不知道怎么看的事实,该方法 testInlining 用在方法 getIvConfig 这在转弯 getIvConfig 用另一种方法prevents内联的 testInlining

But I am not sure to see how the fact that the method testInlining is used in the method getIvConfig which is in turn used by another method prevents the inlining on testInlining in getIvConfig.

推荐答案

这最近的Andr​​oid SDK中禁用所有的优化默认情况下,看到$ {sdk.dir} /tool​​s/proguard/proguard-android.txt:

This recent Android SDK disables all optimizations by default, see ${sdk.dir}/tools/proguard/proguard-android.txt:

-dontoptimize

另一种优化配置只禁止了一些优化,见$ {sdk.dir} /tool​​s/proguard/proguard-android-optimize.txt:

The alternative optimizing configuration only disables a few optimizations, see ${sdk.dir}/tools/proguard/proguard-android-optimize.txt:

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*

您可以指定你的preferred配置在project.properties文件。

You can specify your preferred configuration file in project.properties.

您可以通过添加选项验证其完整的配置ProGuard的使用 -printconfiguration

You can verify which complete configuration ProGuard is using by adding the option -printconfiguration.

一些优化已被禁用,以避免在旧版本的Dalvik虚拟机中的错误(!code /简/算术,!code /简/ CAST),以及一些优化可能已被禁用,以避免在旧版本的ProGuard(!字段/ * ,!类/合并/*).

Some optimizations have been disabled in order to avoid bugs in older versions of the Dalvik VM (!code/simplification/arithmetic,!code/simplification/cast), and some optimizations may have been disabled to avoid bugs in older versions of ProGuard (!field/*,!class/merging/*).

注意 -whyareyoukeeping 指的是收缩步骤,从而消除不必要的类/字段/方法的全过程。未删除的方法可以在优化步骤被内联(除非明确地说明,否则 -keep )。

Note that -whyareyoukeeping refers to the shrinking step, which removes unnecessary classes/fields/methods as a whole. Methods that are not removed may be inlined in the optimization step (unless explicitly specified otherwise with -keep).

这篇关于Android的Proguard的不内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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