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)
To make it possible for application crates to avoid explicitly
depending on the `android-activity` crate (and avoid version conflicts)
this re-exports the android-activity crate under:
`winit::platform::android::activity::*`
This also adds `android-native-activity` and `android-game-activity`
features that set the corresponding android-activity features.
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
+1
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,7 @@ And please only add new entries to the top of this list, right below the `# Unre
28
28
-**Breaking:** Removed `WindowBuilderExtWindows::with_theme` and `WindowBuilderExtWayland::with_wayland_csd_theme` in favour of `WindowBuilder::with_theme`.
29
29
-**Breaking:** Removed `WindowExtWindows::theme` in favour of `Window::theme`.
30
30
- Enabled `doc_auto_cfg` when generating docs on docs.rs for feature labels.
31
+
-**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))
Copy file name to clipboardexpand all lines: README.md
+73-16
Original file line number
Diff line number
Diff line change
@@ -99,36 +99,93 @@ 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
105
+
for defining the main entry point for your Rust application as well as tracking
106
+
various life-cycle events and synchronizing with the main JVM thread.
105
107
106
-
`winit` compatibility table with `ndk-glue`:
108
+
Winit uses the [android-activity](https://github.com/rib/android-activity) as a
|`NativeActivity`|`android-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`|
146
+
|[`GameActivity`]|`android-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`
180
+
For more details, refer to these `android-activity`[example applications](https://github.com/rib/android-activity/tree/main/examples).
181
+
182
+
##### Converting from `ndk-glue` to `android-activity`
183
+
184
+
If your application is currently based on `NativeActivity` via the `ndk-glue` crate and building with `cargo apk` then the minimal changes would be:
185
+
1. Remove `ndk-glue` from your `Cargo.toml`
186
+
2. Enable the `"android-native-activity"` feature for Winit: `winit = { version = "0.28", features = [ "android-native-activity" ] }`
187
+
3. 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).
188
+
4. Pass a clone of the `AndroidApp` that your application receives to Winit when building your event loop (as shown above).
0 commit comments