ProGuard JNI Error

荒凉一梦 提交于 2019-12-12 09:57:43

问题


I'm using ProGuard to obfuscate my Java Desktop application. When I launch the obfuscated JAR, I'm getting the following error:

> java -jar program.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 80
Exception Details:
  Location:
    MyMainClass.a(Ljava/lang/String;)Ljava/lang/String; @40: iflt
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: 0406 7805 0882 8206 0882 0778 0482 0659
    0x0000010: 7808 822a b600 0f59 bc05 0459 585f 0464
    0x0000020: 5b3e 4c36 045b 583d 9b00 282b 2a1d 5ab6
    0x0000030: 000e 8403 ff1c 8292 551d 9b00 162b 2a1d
    0x0000040: 8403 ff5a b600 0e15 0482 9255 1da7 ffdb
    0x0000050: bb00 0659 2bb7 000d b0

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetMethodRecursive(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I'm using the following Maven dependencies in my project:

<dependencies>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>com.github.dblock</groupId>
        <artifactId>oshi-core</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>net.lingala.zip4j</groupId>
        <artifactId>zip4j</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-nop</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>com.google.jimfs</groupId>
        <artifactId>jimfs</artifactId>
        <version>LATEST</version>
    </dependency>
    <dependency>
        <groupId>org.softsmithy.lib</groupId>
        <artifactId>softsmithy-lib-core</artifactId>
        <version>LATEST</version>
    </dependency>
</dependencies>

Also my ProGuard configuration file looks as follows:

-microedition
-dontskipnonpubliclibraryclassmembers
-keepdirectories
-target 1.8
-forceprocessing
-dontoptimize
-allowaccessmodification
-overloadaggressively
-keeppackagenames org.**
-dontpreverify
-verbose
-dontwarn **.**


-keep class org.sqlite.** {
    <fields>;
    <methods>;
}

-keep class com.sun.** {
    <fields>;
    <methods>;
}

-keep class com.google.** {
    <fields>;
    <methods>;
}

-keep class oshi.** {
    <fields>;
    <methods>;
}

# Rest omitted

I tried disabling optimization, preverification, shrinking, obfuscation and also removing the -target 1.8 flag. Only then the error go away.

But I would like to keep all options and not break the output JAR otherwise it's pointless. How do I do that?


回答1:


You are building a Desktop application, thus you need to disable the following option:

-microedition

Additionally, preverification is needed for Java versions 7+, thus you also need to disable:

-dontpreverify

The -target 1.8 can be omitted as well.



来源:https://stackoverflow.com/questions/37321846/proguard-jni-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!