安卓的Proguard的NoSuchMethodError [英] Android: Proguard NoSuchMethodError

查看:176
本文介绍了安卓的Proguard的NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近启动的ProGuard我的Eclipse的Andr​​oid项目。添加外部库和动态引用类的proguard.cfg后,建设APK时,我没有得到任何错误。我得到一个不过时的NoSuchMethodError我尝试启动安装的应用程序。

I recently activated ProGuard for my Eclipse Android project. After adding external libs and dynamically referenced classes to the proguard.cfg, I don't get any errors when building the apk. I get however a NoSuchMethodError when I try to start the installed app.

我把范围缩小到所谓的主要活动的onCreate方法的具体方法。为简单起见,这里是类和方法的样子(我离开了很多code,但我认为这应该说明吧)

I narrowed it down to a specific method called in the onCreate method of the main activity. To simplify things, here's what the class and method look like (I left out a lot of code, but I think this should illustrate it):

public class TestMain extends TabActivity implements OnSharedPreferenceChangeListener{
    ...

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        testMethod();
    }
}

TestMethod的()被定义如下:

testMethod() is defined as follows:

private void testMethod() {
    int charsLeft = maxPostMessageLength - someEditText.length();
    ...
}

当我删除someEditText.length()的一部分,应用程序启动。这样,即无法找到我看到的方式中,该方法是EditText.length()方法。奇怪的是,应用程序也将启动,当我删除someEditText.length()从TestMethod的,并把它直接进入onCreate方法:

When I remove the "someEditText.length()" part, the app starts. So, the way I see it, the method that can't be found is the EditText.length() method. Strangely, though, the app also starts when I remove "someEditText.length()" from the testMethod and put it directly into the onCreate method:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        test = someEditText.length();
        testMethod();
    }

有谁知道我怎么能摆脱这种错误的,为什么我可以在onCreate方法,但不是在一个由onCreate方法调用的方法直接调用someEditText.length()?
如果不使用Proguard的应用程序工作正常,当然。

Does anyone know how I can get rid of this error and why I can call someEditText.length() directly in the onCreate method but not in a method called by the onCreate method? Without using Proguard the app works fine, of course.

编辑:
我试过-dontshrink,-dontobfuscate并在proguard.cfg的-dontoptimzie选项。随着-dontoptimize应用程序启动时没有错误。
然而,究竟是什么原因导致这种特定的错误会很有趣。

I tried the -dontshrink, -dontobfuscate and the -dontoptimzie options in the proguard.cfg. With -dontoptimize the app starts without errors. Still, it would be interesting what exactly causes this specific error.

推荐答案

我无意中偶然发现了一个可能的解决方案。那么,它完全工作在我的情况,所以这是原来的问题的解决方案:
今天,我实现了一些code。与@Override注释,没有工作,在第一。幸运的是,别人已经有同样的问题,一个简单的Eclipse相关的解决方案:
<一href=\"http://stackoverflow.com/questions/1678122/must-override-a-superclass-method-errors-after-importing-a-project-into-eclipse/1678170#1678170\">'Must导入项目到Eclipse 后覆盖一个超类方法错误

I accidentally stumbled upon a possible solution. Well, it totally works in my case, so this IS a solution to the original problem: Today, I implemented some code with @Override annotations, which didn't work, at first. Luckily, someone else already had the same problem and an easy Eclipse-related solution: 'Must Override a Superclass Method' Errors after importing a project into Eclipse

现在,我想,好吧,如果我总是使用Java 1.5的水平之前,为什么不再次尝试ProGuard的,没有-dontoptimize选项,现在我将它设置为1.6。不能伤害...

Now, I thought, well, if I was always using Java level 1.5 before, why not try ProGuard again, without the -dontoptimize option, now that I set it to 1.6. Can't hurt...

和我能说什么,现在应用程序启动时,我没有得到奇怪的错误时EditText.length()被调用的方法。

And what can I say, now the app starts and I don't get the strange error when EditText.length() is called in a method.

这篇关于安卓的Proguard的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆