ajalt / mordant

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

Support for running Mordant in Android #165

Open hick209 opened 4 months ago

hick209 commented 4 months ago

In my company here there are people that are running CliKt inside their test flavor of our Android app, which they use to validate things in some e2e tests we run.

Mordant is a dep of CliKt and it currently does not support Android.

Here is our stack trace of the issue we run into during our test runs with Mordant 2.0.0:

java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-aarch64/libjnidispatch.so) not found in resource path (.)
    at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1059)
    at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:1015)
    at com.sun.jna.Native.<clinit>(Native.java:221)
    at com.sun.jna.Native.load(Native.java:596)
    at com.github.ajalt.mordant.internal.LinuxMppImpls.<init>(JnaMppImplsLinux.kt:44)
    at com.github.ajalt.mordant.internal.MppImplKt.<clinit>(MppImpl.kt:97)
    at com.github.ajalt.mordant.terminal.TerminalDetection.isIntellijRunActionConsole(TerminalDetection.kt:169)
    at com.github.ajalt.mordant.terminal.TerminalDetection.detectTerminal(TerminalDetection.kt:16)
    at com.github.ajalt.mordant.terminal.StdoutTerminalInterface.<init>(StdoutTerminalInterface.kt:17)
    at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:56)
    at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:45)
    at com.github.ajalt.clikt.core.Context$Builder.<init>(Context.kt:227)
    at com.github.ajalt.clikt.core.Context$Companion.build$clikt(Context.kt:312)
    at com.github.ajalt.clikt.core.CliktCommand.createContext(CliktCommand.kt:141)
    at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:487)
    at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:486)
    <our code>

I've looked into the code whether the latest available version and even master would have a fix for this issue, but unfortunately it would not help our use case 😕

ajalt commented 4 months ago

To be clear, based on you stack trace you're asking about Java on android, not any of the androidNative targets?

The first google result for your exception suggests that you may need to manually add a dependency on the aar artifact implementation("net.java.dev.jna:jna:5.13.0@aar"). Give that a try.

hick209 commented 4 months ago

Yes, that's correct, Java on Android.

Thanks a log for pointing it out that this could be a dep issue on our end, if so I apologize the churn.

I know we do have that library as a dep, but maybe we strip it out at some point, because the final .so didn't make into the APK, that I'm certain of.

Let me try some things out here and I'll update this issue with the results.