Skip to content

Commit 23b0dd6

Browse files
authored
move ANDROID_APP to bevy_window (#15585)
# Objective - Remove dependency in bevy_asset to bevy_winit - First step for #15565 ## Solution - the static `ANDROID_APP` and the `android_activity` reexport are now in `bevy_window` ## Migration Guide If you use the `android_activity` reexport from `bevy::winit::android_activity`, it is now in `bevy::window::android_activity`. Same for the `ANDROID_APP` static
1 parent 85dfd72 commit 23b0dd6

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

crates/bevy_asset/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ thiserror = "1.0"
4747
uuid = { version = "1.0", features = ["v4"] }
4848

4949
[target.'cfg(target_os = "android")'.dependencies]
50-
bevy_winit = { path = "../bevy_winit", version = "0.15.0-dev" }
50+
bevy_window = { path = "../bevy_window", version = "0.15.0-dev" }
5151

5252
[target.'cfg(target_arch = "wasm32")'.dependencies]
5353
wasm-bindgen = { version = "0.2" }

crates/bevy_asset/src/io/android.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct AndroidAssetReader;
1717

1818
impl AssetReader for AndroidAssetReader {
1919
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
20-
let asset_manager = bevy_winit::ANDROID_APP
20+
let asset_manager = bevy_window::ANDROID_APP
2121
.get()
2222
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
2323
.asset_manager();
@@ -31,7 +31,7 @@ impl AssetReader for AndroidAssetReader {
3131

3232
async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
3333
let meta_path = get_meta_path(path);
34-
let asset_manager = bevy_winit::ANDROID_APP
34+
let asset_manager = bevy_window::ANDROID_APP
3535
.get()
3636
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
3737
.asset_manager();
@@ -47,7 +47,7 @@ impl AssetReader for AndroidAssetReader {
4747
&'a self,
4848
path: &'a Path,
4949
) -> Result<Box<PathStream>, AssetReaderError> {
50-
let asset_manager = bevy_winit::ANDROID_APP
50+
let asset_manager = bevy_window::ANDROID_APP
5151
.get()
5252
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
5353
.asset_manager();
@@ -76,7 +76,7 @@ impl AssetReader for AndroidAssetReader {
7676
&'a self,
7777
path: &'a Path,
7878
) -> std::result::Result<bool, AssetReaderError> {
79-
let asset_manager = bevy_winit::ANDROID_APP
79+
let asset_manager = bevy_window::ANDROID_APP
8080
.get()
8181
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
8282
.asset_manager();

crates/bevy_derive/src/bevy_main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
1212
TokenStream::from(quote! {
1313
#[no_mangle]
1414
#[cfg(target_os = "android")]
15-
fn android_main(android_app: bevy::winit::android_activity::AndroidApp) {
16-
let _ = bevy::winit::ANDROID_APP.set(android_app);
15+
fn android_main(android_app: bevy::window::android_activity::AndroidApp) {
16+
let _ = bevy::window::ANDROID_APP.set(android_app);
1717
main();
1818
}
1919

crates/bevy_window/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2929
raw-window-handle = "0.6"
3030
smol_str = "0.2"
3131

32+
[target.'cfg(target_os = "android")'.dependencies]
33+
android-activity = "0.6"
34+
3235
[lints]
3336
workspace = true
3437

crates/bevy_window/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ mod window;
2727

2828
pub use crate::raw_handle::*;
2929

30+
#[cfg(target_os = "android")]
31+
pub use android_activity;
32+
3033
pub use event::*;
3134
pub use monitor::*;
3235
pub use system::*;
@@ -188,3 +191,9 @@ pub enum ExitCondition {
188191
/// surprise your users.
189192
DontExit,
190193
}
194+
195+
/// [`AndroidApp`] provides an interface to query the application state as well as monitor events
196+
/// (for example lifecycle and input events).
197+
#[cfg(target_os = "android")]
198+
pub static ANDROID_APP: std::sync::OnceLock<android_activity::AndroidApp> =
199+
std::sync::OnceLock::new();

crates/bevy_winit/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use bevy_derive::Deref;
1818
use bevy_window::{RawHandleWrapperHolder, WindowEvent};
1919
use core::marker::PhantomData;
2020
use winit::event_loop::EventLoop;
21-
#[cfg(target_os = "android")]
22-
pub use winit::platform::android::activity as android_activity;
2321

2422
use bevy_a11y::AccessibilityRequested;
2523
use bevy_app::{App, Last, Plugin};
@@ -52,12 +50,6 @@ mod winit_config;
5250
mod winit_monitors;
5351
mod winit_windows;
5452

55-
/// [`AndroidApp`] provides an interface to query the application state as well as monitor events
56-
/// (for example lifecycle and input events).
57-
#[cfg(target_os = "android")]
58-
pub static ANDROID_APP: std::sync::OnceLock<android_activity::AndroidApp> =
59-
std::sync::OnceLock::new();
60-
6153
/// A [`Plugin`] that uses `winit` to create and manage windows, and receive window and input
6254
/// events.
6355
///
@@ -119,7 +111,7 @@ impl<T: Event> Plugin for WinitPlugin<T> {
119111
{
120112
use winit::platform::android::EventLoopBuilderExtAndroid;
121113
let msg = "Bevy must be setup with the #[bevy_main] macro on Android";
122-
event_loop_builder.with_android_app(ANDROID_APP.get().expect(msg).clone());
114+
event_loop_builder.with_android_app(bevy_window::ANDROID_APP.get().expect(msg).clone());
123115
}
124116

125117
app.init_non_send_resource::<WinitWindows>()

0 commit comments

Comments
 (0)