How to specify a dependency on a third-party JAR+AAR cross-platform library?


I am trying to make a cross-platform (let’s say, desktop Linux + Android) Java library that uses JNA.
JNA is packaged as a module with both a JAR and an AAR, and jar is specified as the default packaging in its maven pom.

The issue is that the JAR build of JNA only works on Linux, and the AAR build of JNA only works on Android, so the right format must be used depending on the platform.

Ideally, I would like to write a build.gradle file for my library such that users on both Linux and Android can use my library by specifying a simple dependency.

If I specify ...jna@jar as the dependency, it won’t build on Android, conversely ...jna@aar won’t build on Linux. ...jna without any format specifier won’t work either because it explicitly falls back to jar.

I feel the only possible way to get around this issue is to maybe specify ...jna in my library, but explicitly ask in a readme that the app that would eventually use my library (possibly indirectly) should enforce that the JNA format used be aar, and have a specific line in its final build.gradle, like: overrideFormat(group='...jna', format='aar') } . Does something like that exist? This reminds me of useVersion, but for a dependency format.

I’d be also happy to hear about a better approach for that.