vivek.m
vivek.m

Reputation: 3321

Proguard setting to not remove unused method

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?

Upvotes: 3

Views: 6650

Answers (2)

Eric Lafortune
Eric Lafortune

Reputation: 45648

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);
}

Upvotes: 6

NickT
NickT

Reputation: 23873

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

Upvotes: 1

Related Questions