如何修复 Android 上的 proguard NoSuchMethodException
我已经混淆了 Lite 和完整的项目,它们都引用了一个库项目。在运行时,我收到“NoSuchMethodException myMethod”错误
根据 http://proguard .sourceforge.net/index.html#/manual/troubleshooting.html 我必须将以下内容添加到 proguard.cfg
-keep class mypackage.MyClass { void myMethod(); }
我的方法返回一个字符串并接受 3 个字符串参数,因此我将以下内容添加到proguard.cfg
-keep public class com.mycompany.appName.MyClass {
String myMethod(String, String, String);
}
但我仍然遇到同样的错误。
假设我正在构建精简版本 com.mycompany.appName.lite,我假设我不必更改添加到 proguard.cfg 的行中的包名称,因为它是一个引用的库。
我有什么遗漏的吗?谢谢。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现调试 ProGuard 是一种黑魔法,您可能需要验证 keep 参数是否确实按照其预期执行。
我一直在使用我创建的探测方法:
http://code.google.com/p/android-beryl/source/browse/beryl-core/src/org/beryl/diagnostics/Log.java
然后我做什么要做的就是监控班级转储到 LogCat 的定义。您还可以查看 proguard/ 目录中的文件以了解发生了什么。但我发现这非常困难。
对于你的情况,我会从一个非常宽松的开始,保留所有内容,然后努力收紧课程。
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
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.
添加到 Jeremy 的从保留整个类开始的解决方案中,我的具体解决方案是在字符串参数前面添加“java.lang”。
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.