There are also rough edges, which will hopefully get polished over time. Most of these should be explained below.
This guide assumes you already have install Cargo and Android Studio (but not that you used both together).
## Installing the requirements
First you'll need to install targets so Rust knows how to compile to Android.
```sh
$ rustup target install armv7-linux-androideabi \
aarch64-linux-android \
i686-linux-android \
x86_64-linux-android
```
You'll also need to get a NDK (you can skip this step if you already have one installed). As of now, NDK 23 is not supported yet.
You can download the NDK 22 [here](https://github.com/android/ndk/wiki/Unsupported-Downloads).
Choose the right NDK for your platform, unzip the archive and set the environment variable `NDK_HOME` to point to your newly installed NDK (you'll need to adjust the path to match your setup).
Install cargo-ndk. It's not technically required, but does make it easier.
```sh
$ cargo install cargo-ndk
```
## Configuring a Rust project
To create a new project in the directory you're in. You can do:
```sh
$ cargo init <project-name> --lib
```
You'll then need to add some content to the Cargo.toml.
First add the subcrates of arti you want to use to the `[dependencies]` section. You'll have to add `features=["static"]` to crates that support this feature
(at the moment tor-rtcompat and tor-dirmgr), otherwise they will fail either to compile or to run.
You'll also need to add `jni`, to allow Rust and the Java in your app to work together.
```toml
jni = { version = "0.19", default-features = false }
```
You'll probably want to add some other dependancies, like futures, but these are not technically requirements.
You'll also need to specify what kind of lib this is. By default, it's a Rust lib that can only be used in the rust ecosystem.
We want it to be a dynamic library:
```toml
[lib]
crate-type = ["dylib"]
```
You are good to start programming in src/lib.rs.
To make your functions available to Java, you need to set some modifier on them, and to name them with a special convention.
You should be familiar with it if you used the JNI before, otherwise it's probably time to learn how to use it.
```rust
// defined the method "myMethod" on class "MyClass" in package "net.example"