[Doc] Improve instructions for building Rust SDK locally (#4015)

* Improve instructions for building Rust SDK locally

* Update _developer_onboarding.md
This commit is contained in:
Richard van der Hoff 2024-12-11 13:34:11 +00:00 committed by GitHub
parent c5e605a539
commit 91444aee67
2 changed files with 43 additions and 38 deletions

View file

@ -83,8 +83,11 @@ You can also come chat with the community in the Matrix [room](https://matrix.to
## Build instructions ## Build instructions
Just clone the project and open it in Android Studio. Just clone the project and open it in Android Studio. Make sure to select the
Makes sure to select the `app` configuration when building (as we also have sample apps in the project). `app` configuration when building (as we also have sample apps in the project).
To build against a local copy of the Rust SDK, see the [Developer
onboarding](docs/_developer_onboarding.md#build-the-sdk-locally) instructions.
## Support ## Support

View file

@ -117,41 +117,43 @@ You can also have access to the aars through the [release](https://github.com/ma
#### Build the SDK locally #### Build the SDK locally
Easiest way: run the script [../tools/sdk/build_rust_sdk.sh](../tools/sdk/build_rust_sdk.sh) and just answer the questions. Prerequisites:
* Install the Android NDK (Native Development Kit). To do this from within
Android Studio:
1. **Tools > SDK Manager**
2. Click the **SDK Tools** tab.
3. Select the **NDK (Side by side)** checkbox
4. Click **OK**.
5. Click **OK**.
6. When the installation is complete, click **Finish**.
* Install `cargo-ndk`:
```
cargo install cargo-ndk
```
* Install the Android Rust toolchain:
```
rustup target add aarch64-linux-android
```
* Depending on the location of the Android SDK, you may need to set
`ANDROID_HOME`:
```
export ANDROID_HOME=$HOME/android/sdk
```
Legacy way: You can then build the Rust SDK by running the script
[`tools/sdk/build_rust_sdk.sh`](../tools/sdk/build_rust_sdk.sh) and just answering
the questions.
If you need to locally build the sdk-android you can use This will prompt you for the path to the Rust SDK, then build it and
the [build](https://github.com/matrix-org/matrix-rust-components-kotlin/blob/main/scripts/build.sh) script. `matrix-rust-components-kotlin`, eventually producing an aar file at
`./libraries/rustsdk/matrix-rust-sdk.aar`, which will be picked up
For this please check the [prerequisites](https://github.com/matrix-org/matrix-rust-components-kotlin/blob/main/README.md#prerequisites) from the repo. automatically by the Element X Android build.
Checkout both [matrix-rust-sdk](https://github.com/matrix-org/matrix-rust-sdk) and [matrix-rust-components-kotlin](https://github.com/matrix-org/matrix-rust-components-kotlin) repositories
```shell
git clone git@github.com:matrix-org/matrix-rust-sdk.git
git clone git@github.com:matrix-org/matrix-rust-components-kotlin.git
```
Then you can launch the build script from the matrix-rust-components-kotlin repository with the following params:
- `-p` Local path to the rust-sdk repository
- `-o` Optional output path with the expected name of the aar file. By default the aar will be located in the corresponding build/outputs/aar directory.
- `-r` Flag to build in release mode
- `-m` Option to select the gradle module to build. Default is sdk.
- `-t` Option to to select an android target to build against. Default will build for all targets.
So for example to build the sdk against aarch64-linux-android target and copy the generated aar to Element X project:
```shell
./scripts/build.sh -p [YOUR MATRIX RUST SDK PATH] -t aarch64-linux-android -o [YOUR element-x-android PATH]/libraries/rustsdk/matrix-rust-sdk.aar
```
Troubleshooting: Troubleshooting:
- You may need to set `ANDROID_NDK_HOME` e.g `export ANDROID_NDK_HOME=~/Library/Android/sdk/ndk`. - You may need to set `ANDROID_NDK_HOME` e.g `export ANDROID_NDK_HOME=~/Library/Android/sdk/ndk`.
- If you get the error `thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', .cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-ndk-2.11.0/src/cli.rs:345:18` try updating your Cargo NDK version. In this case, 2.11.0 is too old so `cargo install cargo-ndk` to install a newer version. - If you get the error `thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', .cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-ndk-2.11.0/src/cli.rs:345:18` try updating your Cargo NDK version. In this case, 2.11.0 is too old so `cargo install cargo-ndk` to install a newer version.
- If you get the error `Unsupported class file major version 64` try changing your JVM version. In this case, Java 20 is not supported in Gradle yet, so downgrade to an earlier version (Java 17 worked in this case). - If you get the error `Unsupported class file major version <n>`, try changing your JVM version by setting
`JAVA_HOME` and, if building via Android Studio, "File | Settings | Build, Execution, Deployment | Build Tools | Gradle | Gradle JDK".
You are good to test your local rust development now!
### The Android project ### The Android project