Proguard-错误:发生了JNI错误 [英] Proguard - Error: A JNI error has occured

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

问题描述

我一直在尝试使用ProGuard混淆我的应用程序.我已经禁用了每个选项的混淆选项.装载程序是我的主要课程.

I've been trying to use ProGuard to obfuscate an application of mine. I have disabled every option exception for obfuscate. Loader is my main class.

下面的屏幕截图是我尝试运行混淆的jar时的结果. 混淆时也没有错误.

The screenshot below is the result when I try to run my obfuscated jar. No errors were given while obfuscating either.

我的配置

-injars 'C:\Users\Corsair\Desktop\obfuscate\Example.jar'
-outjars 'C:\Users\Corsair\Desktop\obfuscate\ExampleOut.jar'

-libraryjars 'C:\Program Files\Java\jre1.8.0_91\lib\rt.jar'

-dontskipnonpubliclibraryclassmembers
-dontshrink
-dontoptimize
-dontusemixedcaseclassnames
-dontpreverify
-dontnote
-dontwarn

-verbose

-keep class Loader

推荐答案

如果这是您正在使用的唯一配置,则本机方法也将变得模糊.结果,它们的名称将不再与本机库中的名称匹配,因此,当尝试使用System.loadLibrary加载库时,您将看到类似的错误.

If this is the only configuration that you are using, also native methods will get obfuscated. As a result, their name will not match the ones in the native library anymore, and thus you will see an error like this when trying to load the library using System.loadLibrary.

您需要至少添加一个这样的规则:

You need to add at least a rule like this:

-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

这将指示ProGuard将所有本机方法保留在它处理的任何类中.

This will instruct ProGuard to keep all native methods in any class it processes.

使其工作所需的其他规则:

Additional rules that are needed to get it working:

  • 删除-dontpreverify,Java 7+需要预验证
  • 保留主要方法
  • Remove -dontpreverify, preverify is needed for Java 7+
  • Keep the main method

这将保留主要方法:

-keep class Loader {
    public static void main(...);
}

这篇关于Proguard-错误:发生了JNI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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