如何避免混淆接口方法在Android中使用Proguard设置其参数? [英] How to not obfuscate interface methods & its parameters using Proguard in Android?

查看:695
本文介绍了如何避免混淆接口方法在Android中使用Proguard设置其参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

public class MyClass {
    public void method1(Integer marks) {

    }

    private String method3(String name){

    }
    public interface interface1 {
        void method4(Integer ID);
        void method5(Integer rate, boolean status);
    }
}

我用过progaurd-rules.pro

I have used progaurd-rules.pro

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keepparameternames

-keep public class *
-keepclassmembers public class *{
   public *;
 }
-keep public interface packageName.MyClass$interface1 { *; }

混淆的代码如下:

public class MyClass {
    public void method1(Integer marks) {

    }

    private String a(String var1){

    }
    public interface interface1 {
        void method4(Integer var1);
        void method5(Integer var1, boolean var2);
    }
}

我希望不要混淆接口方法变量(ID,速率和状态).即如下

I want the interface methods variables (ID, rate & status) not to obfuscate. i.e as below

public interface interface1 {
    void method4(Integer ID);
    void method5(Integer rate, boolean status);
} 

怎么可能?

推荐答案

您可以通过向-keepattributes添加额外的标志来保留方法的参数.他们看起来像这样:

You could keep method's arguments by adding extra flags to -keepattributes. They look like this:

-keepattributes LocalVariableTable,LocalVariableTypeTable

不幸的是,这不仅使参数难以混淆,而且不仅在所需的接口中,而且在整个项目中.也许对您来说很好.

Unfortunately, this keeps arguments from obfuscation not only in the interface you want, but in the entire project. Maybe that's fine for you.

如果您使用的是Android SDK随附的默认proguard配置,则还可以使用特殊的注释来防止混淆某些类. 将其签出.

If you're using a default proguard configuration shipped along with Android SDK then you could also use a special annotation to prevent some classes from obfuscation. Check it out.

这篇关于如何避免混淆接口方法在Android中使用Proguard设置其参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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