0

我正在使用 oshi 在我的应用程序中创建唯一键。我从项目中创建了一个带有 maven 阴影插件的胖 jar。胖罐子工作正常,没有混淆。但是,如果我使用 ProGuard 混淆 jar,则 jar 在尝试运行时会引发以下错误。

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.a.H.h()Ljava/lang/String;
    at com.sun.a.H.h(Native Method)
    at com.sun.a.H.<clinit>(Unknown Source)
    at com.sun.a.ab.setAlignType(Unknown Source)
    at com.sun.a.ab.<init>(Unknown Source)
    at com.sun.a.ab.<init>(Unknown Source)
    at com.sun.a.ab.<init>(Unknown Source)
    at com.sun.a.ab.<init>(Unknown Source)
    at com.sun.a.b.d.aJ.<init>(Unknown Source)
    at com.sun.a.b.d.X.a(Unknown Source)
    at oshi.hardware.platform.windows.WindowsCentralProcessor.initProcessorCounts(Unknown Source)
    at oshi.hardware.common.AbstractCentralProcessor.<init>(Unknown Source)
    at oshi.hardware.platform.windows.WindowsCentralProcessor.<init>(Unknown Source)
    at oshi.hardware.platform.windows.WindowsHardwareAbstractionLayer.createProcessor(Unknown Source)
    at oshi.util.Memoizer$1.get(Unknown Source)
    at oshi.hardware.common.AbstractHardwareAbstractionLayer.getProcessor(Unknown Source)
    at com.pegado.qpguard.f.d.a(Unknown Source)
    at com.pegado.qpguard.d.b.<clinit>(Unknown Source)
    at com.pegado.qpguard.editor.Application.main(Unknown Source)

所以我创建了一个 proguard.confile 来管理混淆规则。

-keep public class com.acme.qpguard.editor.Application { *; }
-keep class org.apache.log4j.** { *; }
-keep class oshi.hardware.** { *; }
-keep class oshi.util.** { *; }
-keep class oshi.software.** { *; }
-keep class oshi.SystemInfo { *; }

但这对我没有帮助。jar 仍然抛出 java.lang.UnsatisfiedLinkError,由 oshi 引起。期待解决这个问题的指针。提前致谢。

4

1 回答 1

0

我已将我的 proguard.conf 修改为:

-dontskipnonpubliclibraryclassmembers
-keepdirectories
-target 1.8
-forceprocessing
-dontoptimize
-allowaccessmodification
#-overloadaggressively
#-keeppackagenames org.**
-keepattributes *Annotation*
-verbose
-keep public class com.acme.qpguard.editor.Application { *; }
-keep class org.apache.logging.log4j.** { *; }
-keepattributes Signature,Annotation
-keep class org.sqlite.** { *; }
-keep class com.sun.** { *; }
-keep class com.google.** { *; }
-keep class oshi.** { *; }
-keep class com.acme.qpguard.logger.LoggerConstants { *; }
-keepclassmembers class com.acme.qpguard.logger.QPLogger {
    QPLogger commonLoggerInstance;
}
-keep class com.acme.qpguard.logger.QPLogger { *; }
#
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keepattributes SourceFile,LineNumberTable
-dontwarn

# absolutely must keep this commented out for production
# -keepattributes SourceFile,LineNumberTable

这可能需要进一步优化甚至更正,但暂时对我有用。谢谢

于 2021-05-20T18:21:35.777 回答