You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Android: rework backend to use android_activity crate
This updates the Android backend to use the android_activity crate instead
of ndk-glue. This solves a few issues:
1. The backend is agnostic of the application's choice of Activity base
class
2. Winit is no longer responsible for handling any Java synchronization
details, since these are encapsulated by the design of
android_activity
3. The backend no longer depends on global / static getters for state
such as the native_window() which puts it in a better position to
support running multiple activities within a single Android process.
4. Redraw requests are flagged, not queued, in a way that avoids taking
priority over user events (resolvesrust-windowing#2299)
Addresses: PR rust-windowing#1892
Addresses: PR rust-windowing#2307
Addresses: PR rust-windowing#2343
Addresses: rust-windowing#2293Resolves: rust-windowing#2299
Copy file name to clipboardexpand all lines: CHANGELOG.md
+12
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,19 @@ Please keep one empty line before and after all headers. (This is required for `
7
7
And please only add new entries to the top of this list, right below the `# Unreleased` header.
8
8
9
9
# Unreleased
10
+
-**Breaking:** On Android, switched to using [`android-activity`](https://github.com/rib/android-activity) crate as a glue layer instead of [`ndk-glue](https://github.com/rust-windowing/android-ndk-rs/tree/master/ndk-glue). See [README.md#Android](https://github.com/rust-windowing/winit#Android) for more details. ([#2444](https://github.com/rust-windowing/winit/pull/2444))
10
11
12
+
# 0.27.3
13
+
14
+
- On Windows, added `WindowExtWindows::set_undecorated_shadow` and `WindowBuilderExtWindows::with_undecorated_shadow` to draw the drop shadow behind a borderless window.
15
+
- On Windows, fixed default window features (ie snap, animations, shake, etc.) when decorations are disabled.
16
+
- On Windows, fixed ALT+Space shortcut to open window menu.
17
+
- On Wayland, fixed `Ime::Preedit` not being sent on IME reset.
18
+
- Fixed unbound version specified for `raw-window-handle` leading to compilation failures.
19
+
- Empty `Ime::Preedit` event will be sent before `Ime::Commit` to help clearing preedit.
20
+
- On X11, fixed IME context picking by querying for supported styles beforehand.
21
+
22
+
>>>>>>> 4943d368 (Android: rework backend to use android_activity crate)
11
23
# 0.27.2 (2022-8-12)
12
24
13
25
- On macOS, fixed touch phase reporting when scrolling.
Copy file name to clipboardexpand all lines: README.md
+56-15
Original file line number
Diff line number
Diff line change
@@ -99,36 +99,77 @@ book].
99
99
100
100
#### Android
101
101
102
-
This library makes use of the [ndk-rs](https://github.com/rust-windowing/android-ndk-rs) crates, refer to that repo for more documentation.
102
+
The Android backend builds on (and exposes types from) the [`ndk`](https://docs.rs/ndk/0.7.0/ndk/) crate.
103
103
104
-
The `ndk-glue` version needs to match the version used by `winit`. Otherwise, the application will not start correctly as `ndk-glue`'s internal `NativeActivity` static is not the same due to version mismatch.
104
+
Native Android applications need some form of "glue" crate that is responsible for defining the main entry point for your Rust application as well as tracking various life-cycle events and synchronizing with the main JVM thread.
105
105
106
-
`winit` compatibility table with `ndk-glue`:
106
+
Winit uses the [android-activity](https://github.com/rib/android-activity) as a glue crate (prior to `0.28` it used [ndk-glue](https://github.com/rust-windowing/android-ndk-rs/tree/master/ndk-glue).
107
107
108
-
| winit | ndk-glue |
109
-
| :---: | :------------------: |
110
-
| 0.24 |`ndk-glue = "0.2.0"`|
111
-
| 0.25 |`ndk-glue = "0.3.0"`|
112
-
| 0.26 |`ndk-glue = "0.5.0"`|
113
-
| 0.27 |`ndk-glue = "0.7.0"`|
108
+
The version of the glue crate that your application depends on _must_ match the version that Winit depends on because the glue crate is responsible for your application's main entrypoint. If Cargo resolves multiple versions they will clash.
109
+
110
+
`winit` glue compatibility table:
111
+
112
+
| winit | ndk-glue |
113
+
| :---: | :--------------------------: |
114
+
| 0.28 |`android-activity = "0.3.0"`|
115
+
| 0.27 |`ndk-glue = "0.7.0"`|
116
+
| 0.26 |`ndk-glue = "0.5.0"`|
117
+
| 0.25 |`ndk-glue = "0.3.0"`|
118
+
| 0.24 |`ndk-glue = "0.2.0"`|
119
+
120
+
_Note: There is unfortunately no ergonomic way to configure Cargo so that it understands that the glue crate is special on Android and to give a clear error if multiple versions are resolved. With `ndk-glue` you will get a runtime failure caused by clashing, global static variables. With `android-activity` you will see a compile-time error due to missing feature flags._
114
121
115
122
Running on an Android device needs a dynamic system library, add this to Cargo.toml:
116
123
117
124
```toml
118
125
[[example]]
119
-
name = "request_redraw_threaded"
126
+
name = "main"
120
127
crate-type = ["cdylib"]
121
128
```
122
129
123
-
And add this to the example file to add the native activity glue:
130
+
All Android applications are based on an `Activity` subclass and the `android-activity` crate is designed to support different choices for this base class. You application must specify the base class it needs via a feature flag:
|`NativeActivity`|`native-activity`| Built-in to Android - making it possible to build some tests/demos without needing to compile any JVM code. Can give a false sense of convenience because it's often not really possible to avoid needing a build system that can compile some JVM code, to at least subclass `NativeActivity`|
135
+
|[`GameActivity`]|`game-activity`| Derives from [`AndroidAppCompat`] which is a defacto standard `Activity` base class that helps support a wider range of Android versions. Will offer integration with [`GameTextInput`] library for soft keyboard support. Requires a build system that can compile Java and fetch Android dependencies from a Maven repository (with [Gradle] being the defacto standard build system for Android applications) |
And run the application with `cargo apk run --example request_redraw_threaded`
165
+
For more details, refer to these `android-activity`[example applications](https://github.com/rib/android-activity/tree/main/examples).
166
+
167
+
##### Converting from `ndk-glue` to `android-activity`
168
+
169
+
If your application is currently based on `NativeActivity` via the `ndk-glue` crate and building with `cargo apk` then the minimal changes would be:
170
+
1. Remove `ndk-glue` from your `Cargo.toml` and add dependency on `android-activity` that specifies the `"native-activity"` feature like: `android-activity = { version = "0.3", features = [ "native-activity" ] }`
171
+
2. Add an `android_main` entrypoint (as above), instead of using the '`[ndk_glue::main]` proc macro from `ndk-macros` (optionally add a dependency on `android_logger` and initialize logging as above).
172
+
3. Pass a clone of the `AndroidApp` that your application receives to Winit when building your event loop (as shown above).
0 commit comments