Menu

#585 Is it possible do not change method name in Obfuscator if keepclassnamembers seted

v5.2
open
nobody
None
5
2015-11-03
2015-11-02
jayzhou
No

I use EventBus in my project, and I found an bug like this

Illegal onEvent method onEventAsync$xxxxx(fx f)

and in EventBus

                            ThreadMode threadMode;
                            if (modifierString.length() == 0) {
                                threadMode = ThreadMode.PostThread;
                            } else if (modifierString.equals("MainThread")) {
                                threadMode = ThreadMode.MainThread;
                            } else if (modifierString.equals("BackgroundThread")) {
                                threadMode = ThreadMode.BackgroundThread;
                            } else if (modifierString.equals("Async")) {
                                threadMode = ThreadMode.Async;
                            } else {
                                if (skipMethodVerificationForClasses.containsKey(clazz)) {
                                    continue;
                                } else {
                                    throw new EventBusException("Illegal onEvent method, check for typos: " + method);
                                }
                            }

so....an exception happend.

yes, I find a happy medium

-keepclassmembers,includedescriptorclasses class ** { public void onEvent*(**); }

but , I compared the obfuscated code, the method name and the param's param are not obfuscated.
If Proguard can improve this, let the methodname just stay what just it is will be great pleasure if keepclassmembers set.

Discussion

  • jayzhou

    jayzhou - 2015-11-02

    My code is

    onEventAsync(ClassA a)
    

    after proGuard

    onEventAsync$xxxxx(Fx x)
    

    in My Proguard-project.text

    -keepclassmembers class ** {
        public void onEvent*(**);
    }
    
     
  • Eric Lafortune

    Eric Lafortune - 2015-11-03

    One of ProGuard's optimizations is probably changing the access flags, parameters, or return type of the method, at which point it also changes the name, to make sure there are no name clashes. Admittedly, this is not respecting the -keepclassmembers setting. I can't see what is happening exactly, but you can check if the following option avoids the problem:

    -optimizations !method/marking/static, !method/removal/parameter
    
     
    • jayzhou

      jayzhou - 2015-11-04

      Thanks for your answer!
      In my code

      public void onEventAsync(ClassA a) {...}
      public void onEventAsync(ClassB b) {...}
      

      after proguard

      public void onEventAsync$fdsxdf(FX fx) {...}
      public void onEventAsync$ljljll(FD fd) {...}
      

      what I want after proguard

      public void onEventAsync(FX fx) {...}
      public void onEventAsync(FD fd) {...}
      

      Any suggest?

       

      Last edit: jayzhou 2015-11-04

Log in to post a comment.