crash with NoSuchMethodError after proguard with method references

后端 未结 4 1105
难免孤独
难免孤独 2021-01-18 01:21

the source code before compile&proguard :

public class IntentSession extends BaseIntentSession {
    @Override
    public void onResume() {
        super         


        
4条回答
  •  离开以前
    2021-01-18 01:55

    This happens when a class is looking for, or directly invoking a method of a given argument via reflection in runtime. Proguard can't warn you about this, because there is no link between the obfuscated class and the consumer class in compile time. You can have something like

    public class AbstractbaseSomething{
    
        public abstract void doStuff();
    
    }
    
    public class iDoStuff{
    
        public void letsGo(Object o){
            Method method = o.getClass().getDeclaredMethod("doStuff");
            // do stuff with the method
        }
    
    }
    

    Since the method is referenced used a string with the name, proguard does not detect it, and in runtime, you get a crash. the only solution is, assuming you can't modify the code, is to avoid obfuscating the method and class.

    (You can check a more realistic example in Ormlite-Android)

提交回复
热议问题