bevy
bevy copied to clipboard
Add features to switch `NativeActivity` and `GameActivity` usage
Objective
Add two features to switch bevy to use NativeActivity or GameActivity on Android, use GameActivity by default.
Also close #12058 and probably #12026 .
Solution
Add two features to the corresponding crates so you can toggle it, like what winit and android-activity crate did.
Changelog
Removed default NativeActivity feature implementation for Android, added two new features to enable NativeActivity and GameActivity, and use GameActivity by default.
Migration Guide
Because cargo-apk is not compatible with GameActivity, building/running using cargo apk build/run -p bevy_mobile_example is no longer possible.
Users should follow the new workflow described in document.
Welcome, new contributor!
Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨
You added a new feature but didn't add a description for it. Please update the root Cargo.toml file.
You added a new feature but didn't update the readme. Please run cargo run -p build-templated-pages -- update features to update it, and commit the file change.
Addendum:
In my tests, bevy with android-game-activity feature enabled runs better than native without any code changes, and I didn't encounter bugs.
bevy with android-game-activity feature enabled runs better than native
ca you be more specific about what better means?
bevy with android-game-activity feature enabled runs better than native
ca you be more specific about what better means?
It can let rust code(originally C++ though) control more stuff on app level without much jni coding
For example, in my tests when sending AppExit event, in Native version it will quit, but it will also cause a crash/segfault(I don't know but maybe can handle it with jni crate)
but in Game version, it will simply quit the game without crashing.
It also has better input handling, etc. can see it here
I think android-game-activity should be part of the default features for the Bevy crate.
Example https://github.com/bevyengine/bevy/blob/main/examples/mobile/Cargo.toml should still work, so it must have one selected if it's not part of the default features
I think
android-game-activityshould be part of the default features for the Bevy crate.
Ugh I just reckoned what this line really means, so forget what I have said. RIP for my comprehension.
Example https://github.com/bevyengine/bevy/blob/main/examples/mobile/Cargo.toml should still work, so it must have one selected if it's not part of the default features
Build these(game, probably with native) examples from android-activity examples might be a good choice since cargo apk is deprecated, as #12026 mentioned.
So if we can add these examples then we can close it too.
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file.
Ok I added android-game-activity as a default feature now🤔
But I'm not sure if cargo apk still works with GameActivity in examples.
Still needs some tweaking...
You added a new feature but didn't update the readme. Please run cargo run -p build-templated-pages -- update features to update it, and commit the file change.
After my tests the original mobile example(used cargo-apk) no longer works with GameActivity, because GameActivity needs the app theme to be the child of Theme.AppCompat but cargo-apk can't recognize it.
So we do need a new example(or probably split them to something like mobile-ios, mobine-android-native, mobile-android-game)
it would be nice to be able to keep a common example for iOS and Android, does the code for game activity differs that much?
it would be nice to be able to keep a common example for iOS and Android, does the code for game activity differs that much?
nope, GameActivity won't change rust code, the reason is GameActivity is the child of AppCompat so the theme must also use the child of it or else it'll crash while cargo-apk can't recognize it.
so if we have to give up cargo-apk, then how to make the new mobile example?
for now, my idea is simply replace the android part with a Android Studio project and use cargo-ndk to generate so files, then build apk with gradle or in the IDE like this
the good side is it can accept both native and game since native doesn't care the app theme.
I tried making a minimal android project to use agdk in examples, but this (probably) requires moving assets and resources into gradle, and I have no idea how to do it🤔
Sorry for the long wait, I had stuck in school before.
I'm still trying to shove a minimum android project into the mobile example, and I've made some progress.
For some reason, the apk can compile, but if you run it, you'll only hear music playing with pitch black on screen(and sometimes pops an ANR window).
If we can solve this...
I figured out why ANR happens
the example must build with --release when using cargo ndk
strange, but it does run normally now
Ok I added working minimal(hope so) android studio project file, and a build.rs to copy libc++_shared.so, but doing so might cause document check fails(also probably need a new readme to indicate what have changed and how to compile android)
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
hm, I tried cargo run -p build-templated-pages -- update examples but it didn't change anything, so it's stuck for now?
I'll draft this due to this problem, and I'll change the example readme accordingly
Try running cargo fmt --all. It's good to clean up regardless, and there's a warning about incorrect line endings, so fixing that might help fix the check-missing-examples-in-docs workflow too.
@BD103, are you able to puzzle out why check-missing-examples-in-docs is failing?
I think it's an issue with newline characters on Windows
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.
The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.