android - 使用 android 运行 proguard 时出现奇怪的错误 "Unexpected error while evaluating instruction"

标签 android proguard

我在使用 android 运行 proguard 时遇到了奇怪的错误。这个错误意味着什么,有什么方法可以解决这个问题,

我正在使用 ProGuard,版本 4.4 安卓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)

最佳答案

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

    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 最后一行有问题!我最终得到了 2 个解决方案。

解决方案#1:不在开头初始化 2 个 bool 变量:

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 个 bool 值。

String state = Environment.getExternalStorageState();

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

对于这种情况,这工作得很好(而且可能更好),但我很高兴我没有在更复杂的函数中遇到这个问题!

关于android - 使用 android 运行 proguard 时出现奇怪的错误 "Unexpected error while evaluating instruction",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6030972/

相关文章:

java - ProGuard 避免接口(interface)实现的混淆

android - 未生成 Crashlytics 映射文件

android - 当我使用proguard并启用minify和shrinkresources时,Retrofit body request是空白的

Android Studio 库项目不生成 Jar 文件

java - 在构建 "maven-plugin"包时如何使用 Proguard 混淆?

android - AdMob+安卓 : String types not allowed (at 'configChanges' with value 'keyboard|key

android - APK 扩展文件下载显示验证的各种进展

android - 未捕获的翻译 SimException : dx. rop.cst.CstInterfaceMethodRef 无法转换为 com.android.dx.rop.cst.CstMethodRef (Proguard)

android - Android ListView 中的多种单元格类型

java - ANDROID 开发的理想硬件要求