Skip to content

Commit

Permalink
Support building and running on Android (#36)
Browse files Browse the repository at this point in the history
* Include vendored source code for `openssl` and `sqlite` so that
  they can be built from source for the Android target.

* Add `login.toml`: a temp hack to specify your username and password
  on platforms where command-line arguments aren't supported,
  such as Android and other mobie platforms.
  * This file should not be committed to version control
    with a valid username and password; hence why it's in .gitignore.

* Switch to `log!()` and `error!()` macros instead of
  `println!()` and `eprintln!()`, which work on Android.

* Export environment variables that the `cc` crate relies on
  to build and link Android-specific native target libraries,
  which currently include openssl and sqlite.
  * These variables only affect builds for Android targets.
  * We have modified the upstream `cargo-makepad` to automatically export
    those environment variables for Android builds, which frees
    the app developer (us) from the burden of having to do so.
* We have also modified the upstream `cargo-makepad`
  to support installing the full Android NDK at the canonical path.
  * See <makepad/makepad#388>

*Add instructions for building and running Robrix on Android.
  • Loading branch information
kevinaboos authored Feb 5, 2024
1 parent 76099cc commit 1c3e2bf
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.vscode

.DS_Store

## Temp hack to support login on mobile platforms.
login.toml
67 changes: 40 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ metadata.makepad-auto-version = "zqpv-Yj-K7WNVK2I8h5Okhho46Q="
[dependencies]
makepad-widgets = { git = "https://github.com/makepad/makepad", branch = "rik" }


anyhow = "1.0"
chrono = "0.4"
clap = { version = "4.0.16", features = ["derive"] }
Expand All @@ -37,6 +38,26 @@ unicode-segmentation = "1.10.1"
url = "2.2.2"


## On Android, we currently build OpenSSL and SQLite from
## the vendored source code, because on macOS hosts there aren't yet
## prebuilt versions readily available, nor easily-configured pkg-config sysroots
## like there are on Linux.
##
## Even though we don't directly depend on these crates in Robrix,
## specifying them here with the `vendored`/`bundled` features
## will cause cargo to enable those features across the entire build
## (called "feature unification", see https://doc.rust-lang.org/cargo/reference/features.html#feature-unification),
## meaning that any other crate that depends on them will also use the vendored versions.
##
## Technically, we don't need these when building for Android on Linux systems,
## but there's no way to specify that in Cargo.toml, so we just always include them.
## Plus, this makes builds more reproducible across host systems,
## and avoids the issue of needing to set up pkg-config sysroots on Linux.
[target.'cfg(target_os = "android")'.dependencies]
openssl = { version = "*", features = ["vendored"] }
rusqlite = { version = "*", features = ["bundled"] }


[package.metadata.docs.rs]
all-features = true

Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Robrix is a Matrix chat client written in Rust to demonstrate the functionality
## Building and Running

[Install Rust](https://www.rust-lang.org/tools/install), and then simply run:
First, [install Rust](https://www.rust-lang.org/tools/install).

Then, on desktop platforms (macOS, Linux, Windows), simply run:
```sh
cargo run -- 'USERNAME' 'PASSWORD' ['HOMESERVER_URL']
```
Expand All @@ -19,6 +21,27 @@ cargo run -- 'USERNAME' 'PASSWORD' ['HOMESERVER_URL']
* The `HOMESERVER_URL` argument is optional and uses the `"https://matrix-client.matrix.org/"` URL by default.


### Building Robrix for Android

1. Install the `cargo-makepad` build tool:
```sh
cargo install --force --git https://github.com/makepad/makepad.git --branch rik cargo-makepad
```

2. Use `cargo-makepad` to install the Android toolchain, with the full NDK:
```sh
cargo makepad android install-toolchain --full-ndk
```

3. Build and run Robrix using `cargo-makepad`:
* Fill in your username and password in the [`login.toml`](login.toml) file.
```sh
cargo makepad android run -p robrix --release
```
* You'll need to connect a physical Android device with developer options enabled, or start up an emulator using Android Studio.
> API version 33 or higher is required, which is Android 13 and up.
## Feature status tracker
These are generally sorted in order of priority. If you're interested in helping out with anything here, please reach out via a GitHub issue or on our Robius matrix channel.
Expand All @@ -40,12 +63,12 @@ These are generally sorted in order of priority. If you're interested in helping
- [ ] Display reactions (annotations)
- [ ] Inline link previews
- [ ] Inline reply view
- [x] Send messages (standalone, no replies)
- [ ] Interactive reaction button, send reactions
- [ ] Reply button, send reply
- [ ] Error display banners: no connection, failure to login, sync timeout.
- [ ] Collapsible/expandable view of contiguous "small" events
- [ ] Encrypted rooms, decrypting messages
- [ ] Sending messages

### Auxiliary/admin features: login, registration, settings
- [ ] Username/password login screen
Expand Down
19 changes: 19 additions & 0 deletions login.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
username = " "
password = " "

### Please fill in your username and password above.
###
### Robrix does not yet have a login splash screen.
### Thus, on desktop platforms, we allow the user to
### pass in a username and password as command line arguments.
###
### However, on mobile platforms, there is no way to reliably
### pass in command line arguments.
### Instead, we enable the mobile apps to read them from a copy
### of this file that is included in the app package files.
###
### Only the two username and password fields are supported.
###
### Note that for obvious reasons you should not commit this file
### or upload it to a public repo with your actual username and password in it.
### Thus, we have added it to the .gitignore file.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl LiveRegister for App {
}
impl LiveHook for App {
fn after_new_from_doc(&mut self, _cx: &mut Cx) {
println!("after_new_from_doc(): starting matrix sdk loop");
log!("after_new_from_doc(): starting matrix sdk loop");
crate::sliding_sync::start_matrix_tokio().unwrap();
}
}
Expand Down
Loading

0 comments on commit 1c3e2bf

Please sign in to comment.