How to use rust code in android
It depends on what you’re trying to do on android. Maybe you want to write native application and build it as APK - then you should google for Java Native Interface and start from there. Or you’re trying to make something that will run, for example, in Termux - then follow usual instructions for cross-compilation.
As for using the compiler itself on Android platform as a host - it’s possible, again, under Termux, with Rust installed from the its-pointless repository (again, google for it to get what you need). Although, this Rust won’t be the last released version and could be sometimes unstable, as of my own experience.
Thanks for your reply.
I want to create shared object in rust and use inside android.
The purpose is to use existing rust code.
Rust/wasm32 is surprisingly powerful. I’m currently working on an iOS/Android app where:
99.9% of the code is in Rust/wasm32
iOS/Android just provide a minimal “shell” for loading a webview + providing some bindings to native APIs
Can you share sample code
How are you going to use this “shared object” in Android? That part should be not different for Rust compared to any other language, and I presume that you already have some sort of plan (otherwise it’s not a question about Rust, but more about the Android in general).
It’s part of a proprietary project; but all you need is to:
- create a webview
- load wasm in webview
- setup native <-> webview <-> rust/wasm communication
My idea create .So file in rust and use in Android
You can find my example android project here:
I updated it month ago to fix build with recent android studio.
It has Java based GUI which call Rust code from
Can you guid us step by step process how it works . how to implement the same.
@Dushistov 's link above links to the readme / installation instructions. What else are you looking for?
This sounds awesome. What’s the developer experience like, can you debug the wasm rust code etc ?
It’s actually really boring (by design). The app is designed to be runnable in browser (so I use chrome dev tools for debugging), and the native app is just for handling payments / ability to download/cache the app.
Great idea ! Do you know any doc ou tutorial for that ?
I was able to make an android application(Chip8 emulator) using rust and react-native. It’s not good enough but it can run
Why it will not work on Android?
it is supporting python , ruby
why not for android ?
It will work on Android - either through the use of webview (google it) and wasm (google wasm-pack), as stated before, or through the JNI (google it, or use the link to rust_swig above). I’m not sure we can assist you further without your problem being narrowed down.