ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
986 stars 34 forks source link

UnsatisfiedLinkError when using proguard #115

Closed Goooler closed 1 year ago

Goooler commented 1 year ago

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 1 year ago

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 1 year ago

Or just bundle the rules file under resource folder?

ajalt commented 1 year ago

If that works, I'd rather do that since the rules are short.