如何告诉ProGuard把一切都在一个特定的包? [英] How to tell ProGuard to keep everything in a particular package?

查看:159
本文介绍了如何告诉ProGuard把一切都在一个特定的包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有很多的活动,并使用本机库了。与Eclipse中产生的ProGuard默认的ProGuard配置中删除的东西 - 鼠标点击的方法,静态成员,回调方法而我的机库使用...它有一个简单的方法来指导ProGuard的,以不会从我的包中取出什么?删除的东西只保存大约2.5%的应用程序的大小,而是完全打破了我的申请。配置,测试和维护它由类类的ProGuard配置将是一个痛苦。

My application has many activities and uses native library too. With the default ProGuard configuration which Eclipse generates ProGuard removes many things - OnClick methods, static members, callback methods which my native library uses... Is it there a simple way to instruct ProGuard to NOT remove anything from my package? Removing things saves only about 2.5% of the application size, but breaks my application completely. Configuring, testing and maintaining it class by class in ProGuard configuration would be a pain.

推荐答案

由于最后的结果我发现,只是保持所有集体成员是不够的,我的应用程序,也没有必要的正确的工作。我addded的设置文件这样的:

As final result I found that just keeping all class members is not enough for the correct work of my application, nor necessary. I addded to the settings file this:

-keepclasseswithmembers class * {
    void onClick*(...);
}
-keepclasseswithmembers class * {
    *** *Callback(...);
}

使用的onClick *的情况是,我的机器人解决所有方法:在的onClick的.xml布局文件属性附加伤害(我开始对所有这些方法用的onClick的名称)

The case with onClick* is for all methods which I address in android:onClick atribute in .xml layout files (I begin the names of all such methods with 'onClick').

与*回调的情况是,我从我的家乡code调用(通过JNI)所有回调方法。我把后缀'回调'的每一个这样的方法的名称。

The case with *Callback is for all callback methods which I call from my native code (through JNI). I place a suffix 'Callback' to the name of every such method.

此外,我添加几行对一些特殊情况下,用我的母语code使用,如变量:

Also I added few rows for some special cases with variables which I use from native code, like:

-keep class com.myapp.mypackage.SomeMyClass {
    *** position;
}

(与名称位置的一类名为SomeMyClass从包com.myapp.mypackage一个varible)

(for a varible with name 'position' in a class with name 'SomeMyClass' from package com.myapp.mypackage)

这一切都是因为这些的onClick,回调等,不仅要present还不停地与他们原来的名称。其他的事情ProGuard的可自由优化。

All this is because these onClick, callback etc. must not only be present but also kept with their original names. The other things ProGuard can optimize freely.

与本地方法的情况下也很重要,但它有一个声明从Eclipse的文件生成:

The case with the native methods is important also, but for it there was a declaration in the generated from Eclipse file:

-keepclasseswithmembernames class * {
    native <methods>;
}

这篇关于如何告诉ProGuard把一切都在一个特定的包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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