I am currently experimenting with cross compiling some of my Haskell projects with nix, with a goal of targeting a number of different mobile platforms (e.x. web, android, ios). My biggest goal right now is cross-compiling to Android, as I have the most experience developing front-ends for that platform.
Since I am not using any of the languages officially supported by Android's NDK, and since I already have an easy hands-off setup (nix) for cross-compiling my project as a statically linked executable for the target architectures, I figured that rather than having to deal with both Haskell's ffi and the JNI -- it would be easier to just bundle an executable with my application's APK, and call that via runtime.exec() or ProcessBuilder, using a simple JSON-based API to marshal data via stdin and stdout. This works fine for me, as I am simply using my Haskell project as a back-end, so I don't need to directly manipulate any Java classes on the Haskell end.
This seems to be possible, as I've found a couple other people who have asked the same question. I've tried a few different approaches (all unsuccessfully so far), but this answer seems to be the most promising so far.
As I'm testing this initially with an emulator, I tried putting my executable in both resources/lib/x86/ (as suggested in the above example), as well as in res/lib/x86, and neither of these options seems to be working for me.
When I run:
File(filesDir).parentFile
.list()
.joinToString(", ")
It looks like there is a lib entry, yet when I run:
File(File(filesDir).parentFile!!, "lib")
.list()
?.joinToString(", ") ?: "Not a dir"
I get "Not a dir". So I am not entirely sure what is going wrong.
My only thought is that the linked accepted answer must be assuming either another build tool, or another android gradle plugin version that lays things out differently.
How would I go about properly accomplishing bundling an executable with an Android executable using a modern android gradle plugin? I am currently using com.android.tools.build:gradle:7.0.1, for what it's worth.
If there were any example gradle projects showing exactly how to do this, that would probably be the most helpful, so that way I can make sure I'm not missing something in my build.gradle.