如何修复 Android 上的 proguard NoSuchMethodException

发布于 2024-11-18 04:48:07 字数 681 浏览 7 评论 0原文

我已经混淆了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我偏爱纯白色 2024-11-25 04:48:07

我发现调试 ProGuard 是一种黑魔法,您可能需要验证 keep 参数是否确实按照其预期执行。

我一直在使用我创建的探测方法:

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

Log.inspectClass(MyClass.class);

然后我做什么要做的就是监控班级转储到 LogCat 的定义。您还可以查看 proguard/ 目录中的文件以了解发生了什么。但我发现这非常困难。

对于你的情况,我会从一个非常宽松的开始,保留所有内容,然后努力收紧课程。

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

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 {
    *;
}
此生挚爱伱 2024-11-25 04:48:07

添加到 Jeremy 的从保留整个类开始的解决方案中,我的具体解决方案是在字符串参数前面添加“java.lang”。

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

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); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文