使用android运行proguard时出现奇怪错误“评估指令时出现意外错误”

时间:2011-05-17 12:47:18

标签: android proguard

我在使用android.what运行proguard时遇到了奇怪的错误。这个错误意味着,有没有办法解决这个问题,

我正在使用ProGuard 4.4版 Android 2.3.1

2011-05-17 17:55:25 - tests] Optimizing...
[2011-05-17 17:55:25 - tests] Proguard returned with error code 1. See console
[2011-05-17 17:55:25 - tests] Unexpected error while evaluating instruction:
[2011-05-17 17:55:25 - tests]   Class       = [com/test/service/DownloadBarCodeService]
[2011-05-17 17:55:25 - tests]   Method      = [onHandleIntent(Landroid/content/Intent;)V]
[2011-05-17 17:55:25 - tests]   Instruction = [170] iload v14
[2011-05-17 17:55:25 - tests]   Exception   = [java.lang.NullPointerException] (null)
[2011-05-17 17:55:25 - tests] Unexpected error while performing partial evaluation:
[2011-05-17 17:55:25 - tests]   Class       = [com/test/service/DownloadBarCodeService]
[2011-05-17 17:55:25 - tests]   Method      = [onHandleIntent(Landroid/content/Intent;)V]
[2011-05-17 17:55:25 - tests]   Exception   = [java.lang.NullPointerException] (null)
[2011-05-17 17:55:25 - tests] java.lang.NullPointerException
[2011-05-17 17:55:25 - tests]   at proguard.evaluation.Variables.iload(Variables.java:228)
[2011-05-17 17:55:25 - tests]   at proguard.evaluation.Processor.visitVariableInstruction(Processor.java:645)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.instruction.VariableInstruction.accept(VariableInstruction.java:306)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:729)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:575)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:533)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:221)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:180)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.LivenessAnalyzer.visitCodeAttribute(LivenessAnalyzer.java:195)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.evaluation.VariableOptimizer.visitCodeAttribute(VariableOptimizer.java:102)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:101)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:79)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:439)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.ProgramClass.accept(ProgramClass.java:281)
[2011-05-17 17:55:25 - tests]   at proguard.classfile.ClassPool.classesAccept(ClassPool.java:114)
[2011-05-17 17:55:25 - tests]   at proguard.optimize.Optimizer.execute(Optimizer.java:764)
[2011-05-17 17:55:25 - tests]   at proguard.ProGuard.optimize(ProGuard.java:325)
[2011-05-17 17:55:25 - tests]   at proguard.ProGuard.execute(ProGuard.java:114)
[2011-05-17 17:55:25 - tests]   at proguard.ProGuard.main(ProGuard.java:499)

5 个答案:

答案 0 :(得分:4)

我遇到了同样的问题。这是原始代码:

    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but
        // all we need to know is we can neither read nor write
        mExternalStorageAvailable = false;
        mExternalStorageWriteable = false;
    }

    return (mExternalStorageAvailable && mExternalStorageWriteable);

Proguard最后一行出了问题!我最终得到了两个解决方案。

解决方案#1:不要在开始时初始化2个布尔变量:

boolean mExternalStorageAvailable;
boolean mExternalStorageWriteable;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but
    // all we need to know is we can neither read nor write
    mExternalStorageAvailable = false;
    mExternalStorageWriteable = false;
}

return (mExternalStorageAvailable && mExternalStorageWriteable);

解决方案#2 返回true / false,而不是设置2个布尔值。

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    return true;
} else {
    return false;
}

对于这种情况,这很好(也可能更好),但我很高兴我没有在更复杂的功能中得到这个问题!

答案 1 :(得分:2)

在撰写本文时,最新版本的ProGuard 4.6版本已经解决了这个问题。否则,您可以在Sourceforge上的ProGuard站点上提交错误报告,最好使用一个简单的测试用例来重现问题。

答案 2 :(得分:0)

为了记录,我遇到了同样的问题。你找到了解决方案吗?

修改 我已设法将其归结为下面的两个if语句。如果我注释掉任何一个if语句,Proguard会成功并且不会抛出NullPointerException

boolean externalStorageAvailable = false;
boolean externalStorageWriteable = false;
...
if (!externalStorageAvailable) {
    throw new IOException("External storage is not available");
}
if (!externalStorageWriteable) {
    throw new IOException("Could not get write access to external storage");
}

如果我反转和布尔值并将它们分配给新变量,Proguard也会成功。这对我有用。

boolean externalStorageAvailable = false;
boolean externalStorageWriteable = false;
...
boolean notAvailable = !externalStorageAvailable;
boolean notWritable = !externalStorageWriteable;
if (notAvailable) {
    throw new IOException("External storage is not available");
}
if (notWritable) {          
    throw new IOException("Could not get write access to external storage");
}

答案 3 :(得分:0)

与Android SDK一起更新到ProGuard的(beta)版本4.10后面临同样的问题。

未设置初始化布尔变量的解决方案解决了我的proguard异常!

答案 4 :(得分:-3)

将它放在项目的project.properties文件

proguard.config = / ECLIPSE / proguard.cfg中的PROJECT NAME