我正在使用 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 引起。期待解决这个问题的指针。提前致谢。