Using SDL2 on Android, with Rust code


my question described in Reddit…

how would you go about linking an external static native code library (i.e. containing Rust code, compiled by cargo) - which needs (presumably) to be called by the SDL2 framework , and which also must call SDL2 APIs - with C/C++ application code in an android build …

I gather that the android version of SDL2 uses it’s own Java stub, so you can’t just use a pure ‘native activity’ approach.

I can see how to compile a pure rust program for a native-activity based example… but not how to adapt the build process give by an SDL2/android native example

What would be the best way to drive such a build… hacking up an SDl2 example? writing a completely different custom makefile that would invoke bits of the NDK & other android tools , and Rust/Cargo to build rust code?

is SDL2 ever used with other AOT languages (eg go-lang?)

any advice or pointers welcome


As I mentioned in the other thread, there is no magic to
NativeActivity. It goes through Java via JNI just like SDL does (and
everybody else). This is how Android works (like it or not).

But that said, if you are just using SDL, then you can ignore the
Java/JNI stuff because SDL does that for you. Rust and pretty much all
languages can talk to the C-ABI.

As for build systems, you will be doing some hacking for Android.

For a reference, check out my Swift on Android talk. You are correctly
insightful that the process is similar with other AOT languages as
Rust. I show an example with SDL, but the talk is focused heavily on
the process of using the C-ABI to be the common communication platform
for everything. I also address JNI for dealing directly with Android
(when your library doesn’t do this for you. And I mention build
systems. (I modified CMake and Gradle/Groovy scripts.)