I'm using oshi for creating a unique key in my application. I have created a fat jar with maven shaded plugin from the project. The fat jar is working fine without obfuscation. But if I obfuscate the jar using ProGuard, the jar is throwing the following error while trying to run.
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)
So I have created a proguard.confile to manage obfuscation rules.
-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 { *; }
But this is not helping me. The jar is still throwing java.lang.UnsatisfiedLinkError, caused by oshi. Looking forward for pointers to solve this issue. Thanks in advance.
I have modified my proguard.conf to:
-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
This may need further optimization or even corrections but working for me for the time being. Thank you