From c18fb60d0222012024db74f1b992cdfa6d44211f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:15:12 +0200 Subject: [PATCH 01/11] update metadata about android --- Cargo.toml | 9 ++++++--- examples/README.md | 9 +++++---- examples/README.md.tpl | 9 +++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 69ec5086a5349..2dd1f8d855d13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1474,12 +1474,15 @@ path = "examples/android/android.rs" hidden = true [package.metadata.android] -apk_label = "Bevy Example" +package = "org.bevyengine.example" +apk_name = "bevyexample" assets = "assets" resources = "assets/android-res" build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] -min_sdk_version = 16 -target_sdk_version = 29 + +[package.metadata.android.sdk] +target_sdk_version = 31 [package.metadata.android.application] icon = "@mipmap/ic_launcher" +label = "Bevy Example" diff --git a/examples/README.md b/examples/README.md index f28805e2e9bd6..f8ef1b27ae045 100644 --- a/examples/README.md +++ b/examples/README.md @@ -356,22 +356,23 @@ When using Bevy as a library, the following fields must be added to `Cargo.toml` ```toml [package.metadata.android] build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] -target_sdk_version = 29 -min_sdk_version = 16 + +[package.metadata.android.sdk] +target_sdk_version = 31 ``` Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. ### Old phones -Bevy by default targets Android API level 29 in its examples which is the +Bevy by default targets Android API level 31 in its examples which is the [Play Store's minimum API to upload or update apps](https://developer.android.com/distribute/best-practices/develop/target-sdk). Users of older phones may want to use an older API when testing. To use a different API, the following fields must be updated in Cargo.toml: ```toml -[package.metadata.android] +[package.metadata.android.sdk] target_sdk_version = >>API<< min_sdk_version = >>API or less<< ``` diff --git a/examples/README.md.tpl b/examples/README.md.tpl index bdc54eb868e89..746eab787c240 100644 --- a/examples/README.md.tpl +++ b/examples/README.md.tpl @@ -108,22 +108,23 @@ When using Bevy as a library, the following fields must be added to `Cargo.toml` ```toml [package.metadata.android] build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] -target_sdk_version = 29 -min_sdk_version = 16 + +[package.metadata.android.sdk] +target_sdk_version = 31 ``` Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. ### Old phones -Bevy by default targets Android API level 29 in its examples which is the +Bevy by default targets Android API level 31 in its examples which is the [Play Store's minimum API to upload or update apps](https://developer.android.com/distribute/best-practices/develop/target-sdk). Users of older phones may want to use an older API when testing. To use a different API, the following fields must be updated in Cargo.toml: ```toml -[package.metadata.android] +[package.metadata.android.sdk] target_sdk_version = >>API<< min_sdk_version = >>API or less<< ``` From 3daf5acfefce97cbecf3bd946ee25f2b20db7c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:17:56 +0200 Subject: [PATCH 02/11] use ndk-glue macro --- crates/bevy_derive/src/bevy_main.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/crates/bevy_derive/src/bevy_main.rs b/crates/bevy_derive/src/bevy_main.rs index 4a2650f36c47f..d4ba9eba0e23d 100644 --- a/crates/bevy_derive/src/bevy_main.rs +++ b/crates/bevy_derive/src/bevy_main.rs @@ -10,19 +10,10 @@ pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream { ); TokenStream::from(quote! { - #[no_mangle] #[cfg(target_os = "android")] - unsafe extern "C" fn ANativeActivity_onCreate( - activity: *mut std::os::raw::c_void, - saved_state: *mut std::os::raw::c_void, - saved_state_size: usize, - ) { - bevy::ndk_glue::init( - activity as _, - saved_state as _, - saved_state_size as _, - main, - ); + #[cfg_attr(target_os = "android", bevy::ndk_glue::main(backtrace = "on", ndk_glue = "bevy::ndk_glue"))] + fn android_main() { + main() } #[no_mangle] From 66960861f556ac2dd904cd233cf8b319e6a38885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:19:39 +0200 Subject: [PATCH 03/11] delay window creation event on android --- crates/bevy_winit/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 88e3f81126bea..4ab437d8c15b2 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -48,9 +48,13 @@ impl Plugin for WinitPlugin { #[cfg(target_arch = "wasm32")] app.add_plugin(web_resize::CanvasParentResizePlugin); let event_loop = EventLoop::new(); + #[cfg(not(target_os = "android"))] let mut create_window_reader = WinitCreateWindowReader::default(); + #[cfg(target_os = "android")] + let create_window_reader = WinitCreateWindowReader::default(); // Note that we create a window here "early" because WASM/WebGL requires the window to exist prior to initializing // the renderer. + #[cfg(not(target_os = "android"))] handle_create_window_events(&mut app.world, &event_loop, &mut create_window_reader.0); app.insert_resource(create_window_reader) .insert_non_send_resource(event_loop); From 093900ea458c9960cb1372b957e8c17b6300b638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:22:02 +0200 Subject: [PATCH 04/11] setup wgpu for compatibility --- examples/android/android.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/android/android.rs b/examples/android/android.rs index 8914232398a04..370c15807068e 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -1,9 +1,22 @@ -use bevy::prelude::*; +use bevy::{ + prelude::*, + render::{ + render_resource::WgpuLimits, + settings::{WgpuSettings, WgpuSettingsPriority}, + }, +}; // the `bevy_main` proc_macro generates the required android boilerplate #[bevy_main] fn main() { App::new() + // This settings use the most compatible settings for wgpu. THey help with compatibilty + // with as many devices as possible + .insert_resource(WgpuSettings { + priority: WgpuSettingsPriority::Compatibility, + limits: WgpuLimits::downlevel_defaults(), + ..default() + }) .add_plugins(DefaultPlugins) .add_startup_system(setup) .run(); From 844bbec2dac81d67d3ccb14418807e140f239efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:28:38 +0200 Subject: [PATCH 05/11] add debugging info --- examples/README.md | 16 ++++++++++++++++ examples/README.md.tpl | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/examples/README.md b/examples/README.md index f8ef1b27ae045..7896598e82292 100644 --- a/examples/README.md +++ b/examples/README.md @@ -363,6 +363,22 @@ target_sdk_version = 31 Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. +### Debugging + +You can view the logs with the following command: + +``` +adb logcat | grep 'RustStdoutStderr\|bevy\|wgpu' +``` + +In case of an error getting a GPU or setting it up, you can try settings logs of `wgpu_hal` to `DEBUG` to get more informations. + +Sometimes, running the app complains about an unknown activity. This may be fixed by uninstalling the application: + +``` +adb uninstall org.bevyengine.example +``` + ### Old phones Bevy by default targets Android API level 31 in its examples which is the diff --git a/examples/README.md.tpl b/examples/README.md.tpl index 746eab787c240..639f8adbe8a25 100644 --- a/examples/README.md.tpl +++ b/examples/README.md.tpl @@ -115,6 +115,22 @@ target_sdk_version = 31 Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. +### Debugging + +You can view the logs with the following command: + +``` +adb logcat | grep 'RustStdoutStderr\|bevy\|wgpu' +``` + +In case of an error getting a GPU or setting it up, you can try settings logs of `wgpu_hal` to `DEBUG` to get more informations. + +Sometimes, running the app complains about an unknown activity. This may be fixed by uninstalling the application: + +``` +adb uninstall org.bevyengine.example +``` + ### Old phones Bevy by default targets Android API level 31 in its examples which is the From a5097e397980cdc438072e48ab6867f8cc284cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:42:26 +0200 Subject: [PATCH 06/11] add language fences --- examples/README.md | 4 ++-- examples/README.md.tpl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/README.md b/examples/README.md index 7896598e82292..9ee6f2c6c0b32 100644 --- a/examples/README.md +++ b/examples/README.md @@ -367,7 +367,7 @@ Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for ot You can view the logs with the following command: -``` +```sh adb logcat | grep 'RustStdoutStderr\|bevy\|wgpu' ``` @@ -375,7 +375,7 @@ In case of an error getting a GPU or setting it up, you can try settings logs of Sometimes, running the app complains about an unknown activity. This may be fixed by uninstalling the application: -``` +```sh adb uninstall org.bevyengine.example ``` diff --git a/examples/README.md.tpl b/examples/README.md.tpl index 639f8adbe8a25..bbb026428a09e 100644 --- a/examples/README.md.tpl +++ b/examples/README.md.tpl @@ -119,7 +119,7 @@ Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for ot You can view the logs with the following command: -``` +```sh adb logcat | grep 'RustStdoutStderr\|bevy\|wgpu' ``` @@ -127,7 +127,7 @@ In case of an error getting a GPU or setting it up, you can try settings logs of Sometimes, running the app complains about an unknown activity. This may be fixed by uninstalling the application: -``` +```sh adb uninstall org.bevyengine.example ``` From 4548677e7e2b5dfe642c7a5619fa7bd17bad619a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 02:54:00 +0200 Subject: [PATCH 07/11] improve comment Co-Authored-By: Alice Cecile --- examples/android/android.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/android/android.rs b/examples/android/android.rs index 370c15807068e..5dc4bf5d36171 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -10,8 +10,8 @@ use bevy::{ #[bevy_main] fn main() { App::new() - // This settings use the most compatible settings for wgpu. THey help with compatibilty - // with as many devices as possible + // This configures the app to use the most compatible rendering settings. + // They help with compatibilty with as many devices as possible. .insert_resource(WgpuSettings { priority: WgpuSettingsPriority::Compatibility, limits: WgpuLimits::downlevel_defaults(), From 60f1df2930df171d7b8bdbee7963d0b9c9375fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 03:13:53 +0200 Subject: [PATCH 08/11] add comment about ndk-glue main macro --- crates/bevy_derive/src/bevy_main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_derive/src/bevy_main.rs b/crates/bevy_derive/src/bevy_main.rs index d4ba9eba0e23d..6ec1363097f25 100644 --- a/crates/bevy_derive/src/bevy_main.rs +++ b/crates/bevy_derive/src/bevy_main.rs @@ -10,6 +10,7 @@ pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream { ); TokenStream::from(quote! { + // use ndk-glue macro to create an activity: https://github.com/rust-windowing/android-ndk-rs/tree/master/ndk-macro #[cfg(target_os = "android")] #[cfg_attr(target_os = "android", bevy::ndk_glue::main(backtrace = "on", ndk_glue = "bevy::ndk_glue"))] fn android_main() { From 9fcab5e69ac16ae1b66f64bdedaeccaad918e152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 04:05:06 +0200 Subject: [PATCH 09/11] fix example on emulator Co-Authored-By: SarthakSingh31 <35749450+SarthakSingh31@users.noreply.github.com> --- Cargo.toml | 4 ++-- examples/README.md | 4 +--- examples/README.md.tpl | 4 +--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2dd1f8d855d13..3a094ff9f3722 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1467,10 +1467,10 @@ hidden = true # Android [[example]] crate-type = ["cdylib"] -name = "android" +name = "android_example" path = "examples/android/android.rs" -[package.metadata.example.android] +[package.metadata.example.android_example] hidden = true [package.metadata.android] diff --git a/examples/README.md b/examples/README.md index 9ee6f2c6c0b32..5b4ac1fc95811 100644 --- a/examples/README.md +++ b/examples/README.md @@ -346,11 +346,9 @@ When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` mus To run on a device setup for Android development, run: ```sh -cargo apk run --example android +cargo apk run --example android_example ``` -:warning: At this time Bevy does not work in Android Emulator. - When using Bevy as a library, the following fields must be added to `Cargo.toml`: ```toml diff --git a/examples/README.md.tpl b/examples/README.md.tpl index bbb026428a09e..dff0e1506cd61 100644 --- a/examples/README.md.tpl +++ b/examples/README.md.tpl @@ -98,11 +98,9 @@ When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` mus To run on a device setup for Android development, run: ```sh -cargo apk run --example android +cargo apk run --example android_example ``` -:warning: At this time Bevy does not work in Android Emulator. - When using Bevy as a library, the following fields must be added to `Cargo.toml`: ```toml From cda3a220c5eca6aa733c25c2edc8b416de1727a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 13:50:06 +0200 Subject: [PATCH 10/11] increase the maximum screen size supported --- examples/android/android.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/android/android.rs b/examples/android/android.rs index 5dc4bf5d36171..6078fc2527a36 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -14,7 +14,11 @@ fn main() { // They help with compatibilty with as many devices as possible. .insert_resource(WgpuSettings { priority: WgpuSettingsPriority::Compatibility, - limits: WgpuLimits::downlevel_defaults(), + limits: WgpuLimits { + // This allows for devices with bigger screens + max_texture_dimension_2d: 8192, + ..WgpuLimits::downlevel_defaults() + }, ..default() }) .add_plugins(DefaultPlugins) From b8398f4e1b1ea3de1c2bb4336c97a4f95175d992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Jun 2022 21:29:13 +0200 Subject: [PATCH 11/11] fix CI job --- .github/workflows/validation-jobs.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/validation-jobs.yml b/.github/workflows/validation-jobs.yml index ec060da4afb1e..1c5e8d553ecd6 100644 --- a/.github/workflows/validation-jobs.yml +++ b/.github/workflows/validation-jobs.yml @@ -52,9 +52,6 @@ jobs: target/ key: ${{ runner.os }}-cargo-build-android-${{ hashFiles('**/Cargo.toml') }} - - name: Uninstall android-31 - run: $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --uninstall "platforms;android-31" - - name: Install Android targets run: rustup target add aarch64-linux-android armv7-linux-androideabi @@ -62,7 +59,7 @@ jobs: run: cargo install --force cargo-apk - name: Build APK - run: cargo apk build --example android + run: cargo apk build --example android_example run-examples-on-windows: runs-on: windows-latest