Proguard setting to not remove unused method

好久不见. 提交于 2019-12-12 09:47:47

问题


Conside the following code structure for android:

package blah;
class A{
    class B{
        public void foo(String s){
        }
    } 
}

How can I tell proguard to not remove or obfuscate foo.
foo is unused function in code at compile time but is run at run-time from another code.

I have tried:

-keep class blah.A.B;

-keepclassmembers class blah.A.B {
  public void foo(String s);
}

etc. but nothing stops Proguard from removing that function. I do not want proguard to change name of 'foo'. Proguard may change the name of class A or class B but not the function name 'foo'. Any suggestions?


回答1:


Almost right. In java bytecode, the $ character separates the names of inner classes and their outer classes (to avoid ambiguities with package names). So, to keep just the method:

-keepclassmembers class blah.A$B {
  public void foo(java.lang.String);
}



回答2:


I have a method 'myClickHandler' referenced only in an xml file.

This

-keepclassmembers class * extends android.app.Activity {
    public void myClickHandler(android.view.View );
}

stops it being removed in my application. Perhaps the extends .. will work for you



来源:https://stackoverflow.com/questions/9298992/proguard-setting-to-not-remove-unused-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!