UnsatisfiedLinkError when using proguard
Goooler opened this issue · 3 comments
Goooler commented
I'm using clikt in Diffuse with ProGuard minify enabled, output:
./diffuse diff --jar diffuse-0.2.0-SNAPSHOT-java11.jar diffuse-0.2.0-SNAPSHOT-java16.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't obtain static method dispose from class com.sun.jna.Native
at com.sun.jna.Native.initIDs(Native Method)
at com.sun.jna.Native.<clinit>(SourceFile:248)
at com.github.ajalt.mordant.internal.MacosMppImpls.<init>(SourceFile:46)
at com.github.ajalt.mordant.internal.MppImplKt.<clinit>(SourceFile:98)
at com.github.ajalt.mordant.terminal.TerminalDetection.detectTerminal(SourceFile:143)
at com.github.ajalt.mordant.terminal.StdoutTerminalInterface.<init>(SourceFile:17)
at com.github.ajalt.mordant.terminal.Terminal.<init>(SourceFile:56)
at com.github.ajalt.mordant.terminal.Terminal.<init>(SourceFile:45)
at com.github.ajalt.clikt.core.Context$Builder.<init>(SourceFile:227)
at com.github.ajalt.clikt.core.CliktCommand.createContext(SourceFile:312)
at com.github.ajalt.clikt.core.CliktCommand.parse$default(SourceFile:456)
at com.jakewharton.diffuse.Diffuse.main(SourceFile:475)
Workaround is to add keep rules in config:
# https://github.com/java-native-access/jna/issues/1187#issuecomment-626251894
-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }
I'm wondering if we can add rules into https://github.com/ajalt/mordant/blob/master/mordant/src/jvmMain/resources/META-INF/native-image/com/github/ajalt/mordant/reflect-config.json?
ajalt commented
That file is for graal, I don't think proguard looks at it.
This isn't really a bug in mordant, but we could potentially mention those rules in the docs for the people who use proguard.
Goooler commented
Or just bundle the rules file under resource folder?
ajalt commented
If that works, I'd rather do that since the rules are short.