开发者

How to fix proguard NoSuchMethodException on Android

开发者 https://www.devze.com 2023-03-16 03:17 出处:网络
I have obfuscated Lite and a full projects both referencing a library project. At runtime I\'m getting \"NoSuchMethodException myMethod\" error

I have obfuscated Lite and a full projects both referencing a library project. At runtime I'm getting "NoSuchMethodException myMethod" error

According to http://proguard.sourceforge.net/index.html#/manual/troubleshooting.html I have to add the following to the proguard.cfg

-keep class mypackage.MyClass { void myMethod(); }

My method returns a String and accepts 3 String parameters 开发者_StackOverflow社区so I have added the following to the proguard.cfg

-keep public class com.mycompany.appName.MyClass { 
  String myMethod(String, String, String); 
}

But I still get the same error.

Let's say I'm building the lite version com.mycompany.appName.lite, I'm assuming I don't have to change the package name in the line added to the proguard.cfg since it is a referenced library.

Is there anything I'm missing? Thanks.


I find that debugging ProGuard is black magic you may need to verify that the keep parameters are actually doing what they intend to.

I've been using a probe method I created:

http://code.google.com/p/android-beryl/source/browse/beryl-core/src/org/beryl/diagnostics/Log.java

Log.inspectClass(MyClass.class);

What I then do is monitor the class definition that's dumped out to LogCat. You can also look at the files in the proguard/ directory to figure out what happened. But I find this very difficult.

Fo your case I'd start with a very loose keep everything first and then work to tighten up the class.

-keep class com.mycompany.appName.MyClass {
    *;
}


Adding to Jeremy's solution of starting with keeping the whole class, the specific solution for me was to add the "java.lang" infront of the String arguments.

-keep public class com.mycompany.appName.myClass {
  java.lang.String myMethod(java.lang.String, java.lang.String, java.lang.String); 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消