-
Notifications
You must be signed in to change notification settings - Fork 781
Documentation for Mobile Development #10117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
37866df
Grouped mobile platforms into their own category, started writing an …
anlumo 4c1a731
Added general documentation for mobile development.
anlumo ca929d9
Fixed relative path reference in iOS documentation.
anlumo 45dcf89
Added basic documentation on how to develop for Android.
anlumo 55897db
License information for the mobile documentation screenshots.
anlumo 15d8816
Moved Android screenshots to assets directory.
anlumo 6f0d037
Spelling fixes and incorporated lots of change requests by Simon.
anlumo 5d9a6b9
Found an instance where iOS was mentioned first, contrary to the writ…
anlumo 1138e57
Moved the reuse definition since the image files were moved.
anlumo 6633774
Use the Link element instead of Markdown syntax to link to the refere…
anlumo 3ea5736
Moved information about the safe area from the moblie guide to the re…
anlumo 60b713c
More feedback.
anlumo eee7065
Automate always inserting the current Slint version in the Android docs.
anlumo 06baccc
Use CC-BY-4.0 for the Android/Android Studio screenshots.
anlumo 078eaa0
Fix compilation issues in examples.
anlumo 6c85084
Regenerate the list of documentation files when the astro config chan…
anlumo 8a1b9fd
Fix mobile ScrollView example to get doctests to pass.
anlumo 98f66f4
Hardcode slint version in Android docs, but replace during deployment.
anlumo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,3 +283,9 @@ path = ["ui-libraries/material/src/ui/icons/**.svg", "ui-libraries/material/exam | |
| precedence = "aggregate" | ||
| SPDX-FileCopyrightText = "Material Icons <https://github.com/material-icons/material-icons/blob/master/LICENSE>" | ||
| SPDX-License-Identifier = "Apache-2.0" | ||
|
|
||
| [[annotations]] | ||
| path = ["docs/astro/src/content/docs/guide/platforms/mobile/**.png"] | ||
| precedence = "aggregate" | ||
| SPDX-FileCopyrightText = "Copyright © SixtyFPS GmbH <[email protected]>" | ||
| SPDX-License-Identifier = "Unlicense" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
189 changes: 189 additions & 0 deletions
189
docs/astro/src/content/docs/guide/platforms/mobile/android.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| --- | ||
| <!-- Copyright © SixtyFPS GmbH <[email protected]> ; SPDX-License-Identifier: MIT --> | ||
| title: Android | ||
| description: Android Platform Guide | ||
| --- | ||
|
|
||
| import LangRefLink from '@slint/common-files/src/components/LangRefLink.astro'; | ||
|
|
||
| :::note[Note] | ||
| When developing Slint applications for Android, you can only use Rust as the programming language. | ||
| ::: | ||
|
|
||
| Also see the documentation of the <LangRefLink lang="rust-slint" relpath="android/">android module in our Rust API documentation</LangRefLink>. | ||
|
|
||
| ## Project Setup | ||
|
|
||
| Slint uses the [android-activity crate](https://github.com/rust-mobile/android-activity) as the interface to | ||
| the operating system, which is re-exported as `slint::android::android_activity`. So, you need to follow the same steps to get started. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| First, your project needs to be a library crate. Add the following to your `Cargo.toml`: | ||
|
|
||
| ```toml | ||
| [lib] | ||
| crate_type = ["cdylib"] | ||
| ``` | ||
|
|
||
| You also need to select the version of android-activity you want to use. This is done by selecting one of these | ||
| two features on the Slint crate: | ||
|
|
||
| * `backend-android-activity-06` (version 0.6.x) | ||
| * `backend-android-activity-05` (version 0.5.x) | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For example: | ||
|
|
||
| ```toml | ||
| [dependencies] | ||
| slint = { version = "...", features = ["backend-android-activity-06"] } | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| Unless you depend on version 0.5 due to some other crate, we recommend to use `backend-android-activity-06`. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This feature is ignored for any target\_os that is not Android. So, it can safely be enabled anywhere. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Second, in your `lib.rs`, add this function: | ||
|
|
||
| ```rs | ||
| #[cfg(target_os = "android")] | ||
| #[unsafe(no_mangle)] | ||
| fn android_main(app: slint::android::AndroidApp) { | ||
| slint::android::init(app).unwrap(); | ||
| let main_window = ...; // window generated by the Slint macros | ||
| main_window.run().unwrap(); | ||
| } | ||
| ``` | ||
|
|
||
| You can also add an Android event | ||
| ([`android_activity::PollEvent`](https://docs.rs/android-activity/latest/android_activity/enum.PollEvent.html)) | ||
| listener by replacing the call to `slint::android::init` with `slint::android::init_with_event_listener`. | ||
|
|
||
| That's it! | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Android Setup | ||
|
|
||
| The Android development workflow centers around the `adb` command line tool. With it, you can connect to | ||
| Android devices and emulators to upload and run applications (and do other things not relevant here). | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The easiest way to install the Android development environment is to download and install | ||
| [Android Studio](https://developer.android.com/studio). It contains an SDK manager in its settings pane | ||
| that enables you to download and install all SDK versions you need. Usually it's recommended to use the | ||
| latest version available, because they can be configured to be backwards-compatible with older versions | ||
| of Android. This manager is available in the settings in "Languages & Frameworks" > "Android SDK". | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| Also note the SDK location on top, this path might have to be used for the `ANDROID_HOME` environment | ||
| variable if the build tools can't detect it automatically. | ||
|
|
||
| Also, the directory platform-tools in that location contains the adb tool mentioned above, and so | ||
| should be added to your PATH (the way to do this depends on your development platform and is outside | ||
| the scope of this guide). | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To get the list of Android devices, simulators and emulators currently attached to your machine, run | ||
|
|
||
| ```sh | ||
| > adb devices | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| You can connect to a physical device on the network by using | ||
|
|
||
| ```sh | ||
| > adb connect <host> | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| The `host` is the IP address of the device. Note that it has to have development mode enabled for | ||
| this. | ||
|
|
||
| ### Virtual Device Setup | ||
|
|
||
| We recommand developing using a virtual device first, because it speeds up the development cycle. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| However, eventually you have to also test on a device to make sure that the interface is usable on a | ||
| touch screen and to check if all text is large enough, etc. | ||
|
|
||
| To create and run a virtual device, use the Virtual Device Manager available in Android Studio. You | ||
| can open it from its main screen under "More Actions": | ||
|
|
||
|  | ||
|
|
||
| You can create any number of devices with different configurations here: | ||
|
|
||
|  | ||
|
|
||
| A good approach is to have one device with the minimum API level supported by your application and | ||
| another one with the latest release to make sure it runs on both. | ||
|
|
||
| Running virtual devices should be connected to `adb` automatically. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Virtual Keyboard | ||
|
|
||
| Note that depending on the device template you pick, the virtual devices created here might use a | ||
| hardware keyboard by default, which is not helpful for testing your application. Unfortunately, we | ||
| were unable to locate a way to disable it in the Virtual Device Manager directly. | ||
|
|
||
| To fix this, click on the three vertical dots next to the device in the manager to open up the menu | ||
| and select "Show on disk". In the directory that now opens, open the file `config.ini` in your | ||
| favorite text editor. Navigate to the line `hw.keyboard=yes` and change it to `hw.keyboard=no`, then | ||
| save the file. | ||
|
|
||
| The next challenge is that there is still no keyboard: | ||
|
|
||
|  | ||
|
|
||
| You have to disable the stylus input. Go to the keyboard settings: | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| Select "Write in textfields" in the list and then disable that feature. This should enable the | ||
| regular virtual keyboard. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Running the Application | ||
|
|
||
| There are multiple ways to build, upload and run Android apps written in Rust. This page describes using | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [xbuild](https://github.com/rust-mobile/xbuild). This does not use Android Studio at all. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| At the time of this writing, the current version of xbuild (0.2.0) is severly outdated and contains | ||
| relevant bugs that have been fixed in the master branch. So, don't use `cargo install xbuild` to | ||
| install it, clone the repository and use `cargo install --path .` while in the clone. | ||
anlumo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The command line tool for xbuild is simply called `x`. For example, to get a list of devices connected, | ||
| use | ||
|
|
||
| ```sh | ||
| x devices | ||
| ``` | ||
|
|
||
| Note that unlike `adb` above, this tool also supports iOS devices and simulators. However, for Android | ||
| devices it simply talks to `adb`, so if you connect a device using that tool, it will also show up here. | ||
|
|
||
| To build your project, navigate to the directory containing your `Cargo.toml` and run | ||
|
|
||
| ```sh | ||
| x run --device <id> | ||
| ``` | ||
|
|
||
| Where `<id>` is shown in `x devices` as the leftmost column and is something like `adb:emulator-1234` | ||
| for virtual Android devices. | ||
|
|
||
| This should build your project, upload it to the device and run it. The target platform is detected | ||
| automatically. | ||
|
|
||
| To recompile and test changes, press ctrl-c and run the same command again. The running version on the | ||
| device is replaced automatically. | ||
|
|
||
| #### Troubleshooting | ||
|
|
||
| If `x run` doesn't work, run `x doctor` to check if you have all required tools installed and that | ||
| they're found by xbuild. | ||
|
|
||
| ### Building | ||
|
|
||
| There are many ways to distribute Android applications and xbuild supports all of them via `x build`. | ||
| To get information about the configuration, use `x build --help`. | ||
|
|
||
| For example, to build an .apk file, use something like | ||
|
|
||
| ```sh | ||
| x build --platform android --arch arm64 --format apk --release | ||
| ``` | ||
|
|
||
| The apk is then located in `target/x/release/android/<name>.apk`. | ||
Binary file added
BIN
+82.6 KB
docs/astro/src/content/docs/guide/platforms/mobile/android_keyboard_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+146 KB
docs/astro/src/content/docs/guide/platforms/mobile/android_sdk_manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.1 KB
...stro/src/content/docs/guide/platforms/mobile/android_virtual_device_manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.6 KB
...src/content/docs/guide/platforms/mobile/android_virtual_device_manager_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+54.1 KB
...tro/src/content/docs/guide/platforms/mobile/android_virtual_keyboard_stylus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.