Skip to content

Commit 5515c93

Browse files
authored
[Doc] Improve instructions for building Rust SDK locally (#4015)
* Improve instructions for building Rust SDK locally * Update _developer_onboarding.md
1 parent 4e70c7e commit 5515c93

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Element X Android supports many languages. You can help us to translate the app
5959

6060
Note that for now, we keep control on the French and German translations.
6161

62-
Translations can be checked screen per screen using our tool Element X Android Gallery, available at https://element-hq.github.io/element-x-android/. Note that this page is updated every Tuesday.
62+
Translations can be checked screen per screen using our tool Element X Android Gallery, available at https://element-hq.github.io/element-x-android/. Note that this page is updated every Tuesday.
6363

6464
More instructions about translating the application can be found at [CONTRIBUTING.md](CONTRIBUTING.md#strings).
6565

@@ -83,8 +83,11 @@ You can also come chat with the community in the Matrix [room](https://matrix.to
8383

8484
## Build instructions
8585

86-
Just clone the project and open it in Android Studio.
87-
Makes sure to select the `app` configuration when building (as we also have sample apps in the project).
86+
Just clone the project and open it in Android Studio. Make sure to select the
87+
`app` configuration when building (as we also have sample apps in the project).
88+
89+
To build against a local copy of the Rust SDK, see the [Developer
90+
onboarding](docs/_developer_onboarding.md#build-the-sdk-locally) instructions.
8891

8992
## Support
9093

docs/_developer_onboarding.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ From these kotlin bindings we can generate native libs (.so files) and kotlin cl
102102

103103
#### Matrix Rust Component Kotlin
104104

105-
To use these bindings in an android project, we need to wrap this up into an android library (as the form of an .aar file).
106-
This is the goal of https://github.com/matrix-org/matrix-rust-components-kotlin.
105+
To use these bindings in an android project, we need to wrap this up into an android library (as the form of an .aar file).
106+
This is the goal of https://github.com/matrix-org/matrix-rust-components-kotlin.
107107
This repository is used for distributing kotlin releases of the Matrix Rust SDK.
108108
It'll provide the corresponding aar and also publish them on maven.
109109

@@ -117,41 +117,43 @@ You can also have access to the aars through the [release](https://github.com/ma
117117

118118
#### Build the SDK locally
119119

120-
Easiest way: run the script [../tools/sdk/build_rust_sdk.sh](../tools/sdk/build_rust_sdk.sh) and just answer the questions.
121-
122-
Legacy way:
123-
124-
If you need to locally build the sdk-android you can use
125-
the [build](https://github.com/matrix-org/matrix-rust-components-kotlin/blob/main/scripts/build.sh) script.
126-
127-
For this please check the [prerequisites](https://github.com/matrix-org/matrix-rust-components-kotlin/blob/main/README.md#prerequisites) from the repo.
128-
129-
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
130-
```shell
131-
git clone [email protected]:matrix-org/matrix-rust-sdk.git
132-
git clone [email protected]:matrix-org/matrix-rust-components-kotlin.git
133-
```
134-
135-
Then you can launch the build script from the matrix-rust-components-kotlin repository with the following params:
136-
137-
- `-p` Local path to the rust-sdk repository
138-
- `-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.
139-
- `-r` Flag to build in release mode
140-
- `-m` Option to select the gradle module to build. Default is sdk.
141-
- `-t` Option to to select an android target to build against. Default will build for all targets.
142-
143-
So for example to build the sdk against aarch64-linux-android target and copy the generated aar to Element X project:
144-
145-
```shell
146-
./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
147-
```
120+
Prerequisites:
121+
* Install the Android NDK (Native Development Kit). To do this from within
122+
Android Studio:
123+
1. **Tools > SDK Manager**
124+
2. Click the **SDK Tools** tab.
125+
3. Select the **NDK (Side by side)** checkbox
126+
4. Click **OK**.
127+
5. Click **OK**.
128+
6. When the installation is complete, click **Finish**.
129+
* Install `cargo-ndk`:
130+
```
131+
cargo install cargo-ndk
132+
```
133+
* Install the Android Rust toolchain:
134+
```
135+
rustup target add aarch64-linux-android
136+
```
137+
* Depending on the location of the Android SDK, you may need to set
138+
`ANDROID_HOME`:
139+
```
140+
export ANDROID_HOME=$HOME/android/sdk
141+
```
142+
143+
You can then build the Rust SDK by running the script
144+
[`tools/sdk/build_rust_sdk.sh`](../tools/sdk/build_rust_sdk.sh) and just answering
145+
the questions.
146+
147+
This will prompt you for the path to the Rust SDK, then build it and
148+
`matrix-rust-components-kotlin`, eventually producing an aar file at
149+
`./libraries/rustsdk/matrix-rust-sdk.aar`, which will be picked up
150+
automatically by the Element X Android build.
148151

149152
Troubleshooting:
150153
- You may need to set `ANDROID_NDK_HOME` e.g `export ANDROID_NDK_HOME=~/Library/Android/sdk/ndk`.
151154
- 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.
152-
- 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).
153-
154-
You are good to test your local rust development now!
155+
- If you get the error `Unsupported class file major version <n>`, try changing your JVM version by setting
156+
`JAVA_HOME` and, if building via Android Studio, "File | Settings | Build, Execution, Deployment | Build Tools | Gradle | Gradle JDK".
155157

156158
### The Android project
157159

@@ -262,7 +264,7 @@ Here are the main points:
262264

263265
#### Template and naming
264266

265-
This documentation provides you with the steps to install and use the AS plugin for generating modules in your project.
267+
This documentation provides you with the steps to install and use the AS plugin for generating modules in your project.
266268
The plugin and templates will help you quickly create new features with a standardized structure.
267269

268270
A. Installation
@@ -276,7 +278,7 @@ Follow these steps to install and configure the plugin and templates:
276278
- Navigate to File/Manage IDE Settings/Import Settings
277279
- Pick the `tmp/file_templates.zip` files
278280
- Click on OK
279-
4. Configure generate-module-from-template plugin :
281+
4. Configure generate-module-from-template plugin :
280282
- Navigate to AS/Settings/Tools/Module Template Settings
281283
- Click on + / Import From File
282284
- Pick the `tools/templates/FeatureModule.json`
@@ -296,9 +298,9 @@ Example for a new feature called RoomDetails:
296298
5. The modules api/impl should be created under `features/roomdetails` directory.
297299
6. Sync project with Gradle so the modules are recognized (no need to add them to settings.gradle).
298300
7. You can now add more Presentation classes (Events, State, StateProvider, View, Presenter) in the impl module with the `Template Presentation Classes`.
299-
To use it, just right click on the package where you want to generate classes, and click on `Template Presentation Classes`.
301+
To use it, just right click on the package where you want to generate classes, and click on `Template Presentation Classes`.
300302
Fill the text field with the base name of the classes, ie `RootRoomDetails` in the `root` package.
301-
303+
302304

303305
Note that naming of files and classes is important, since those names are used to set up code coverage rules. For instance, presenters MUST have a
304306
suffix `Presenter`,states MUST have a suffix `State`, etc. Also we want to have a common naming along all the modules.

0 commit comments

Comments
 (0)