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
Objective
- Only use a single modern and better documented android example
- Fix#10945
- Fix#17122
Problems with current examples
- We are currently using deprecated functions like for example [setSystemUiVisibility(int)](https://developer.android.com/reference/android/view/View#setSystemUiVisibility(int)).
- Most Android dependencies are very out of date.
- Kotlin is the [preffered language](https://developer.android.com/kotlin/first) for Android and we should migrate the examples to it.
- Most of the code in the examples is not inherently clear and there are very few comments especially in the build scripts.
- We should only have a single Android example using `games-activity` and `cargo-ndk`. It is confusing and unnecessary to do it any other way in my opinion.
- The crash from #10945 is fixed by migrating to `games-activity` 4. Before this PR, we were using `games-activity` 2. #17122 is apparently also fixed because of this.
Solution
- Replace all android examples with `./examples/mobile/android`
- Update dependencies in `libs.versions.toml`
- Add `gradle-daemon-jvm.properties` generated with `./gradlew updateDaemonJvm`
- Update gradle wrapper
- Migrate everything to kotlin/kotlin build scripts
- Use supported functions instead of deprecated ones
- Move `/assets/ic_launcher.png` to `/examples/mobile/android/app/src/main/res/mipmap/ic_launcher.png` because that is where it is [meant to be stored](https://developer.android.com/guide/topics/resources/providing-resources).
- Use `--link-libcxx-shared` flag for `cargo-ndk` in `examples/README.md`
- Use `targetSdk = 36` and `compileSdk = 36` and explain in `examples/README.md`
Setting the output path ensures the shared object files can be found in target-specific directories under `jniLibs` where the JNI can find them.
@@ -123,21 +126,14 @@ See the `cargo-ndk` [README](https://crates.io/crates/cargo-ndk) for other optio
123
126
After this you can build it with`gradlew`:
124
127
125
128
```sh
129
+
cd ./android
126
130
./gradlew build
127
131
```
128
132
129
133
Or build it with Android Studio.
130
134
131
135
Then you can test it in your Android project.
132
136
133
-
##### About `libc++_shared.so`
134
-
135
-
Bevy may require `libc++_shared.so` to run on Android, as it is needed by the `oboe` crate, but typically `cargo-ndk` does not copy this file automatically.
136
-
137
-
To include it, you can manually obtain it from NDK source or use a `build.rs` script for automation, as described in the `cargo-ndk` [README](https://github.com/bbqsrc/cargo-ndk?tab=readme-ov-file#linking-against-and-copying-libc_sharedso-into-the-relevant-places-in-the-output-directory).
138
-
139
-
Alternatively, you can modify project files to include it when building an APK. To understand the specific steps taken in this project, please refer to the comments within the project files for detailed instructions(`app/CMakeList.txt`, `app/build.gradle`, `app/src/main/cpp/dummy.cpp`).
In its examples, Bevy targets the minimum Android API that Play Store <!-- markdown-link-check-disable -->
160
-
[requires](https://developer.android.com/distribute/best-practices/develop/target-sdk) to upload and update apps. <!-- markdown-link-check-enable -->
161
-
Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameActivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to `NativeActivity`.
155
+
In its example, Bevy targets the newest stable Android API to be able to benefit from security and performance improvements. The example also specifies Android API 31 as minimum SDK to support older devices which is recommended on [Android Developers](https://developer.android.com/google/play/requirements/target-sdk#why-target).
162
156
163
-
To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this:
157
+
Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameActivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to [`NativeActivity`](https://developer.android.com/reference/android/app/NativeActivity).
158
+
159
+
To use `NativeActivity`, you need to write a custom `MainActivity.kt` using `NativeActivity`and add the `android-native-activity` feature to Bevy in your `Cargo.toml` like this:
164
160
165
161
```toml
166
-
bevy = { version = "0.14", default-features = false, features = ["android-native-activity", ...] }
162
+
bevy = { version = "*", default-features = false, features = ["android-native-activity", <...>] }
167
163
```
168
164
169
165
Then build it as the [Build & Run](#build--run) section stated above.
170
166
171
-
##### About `cargo-apk`
172
-
173
-
You can also build an APK with`cargo-apk`, a simpler and deprecated tool which doesn't support `GameActivity`. If you want to use this, there is a [folder](./mobile/android_basic) inside the mobile example with instructions.
174
-
175
-
Example | File | Description
176
-
--- | --- | ---
177
-
`android`| [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
Setting the output path ensures the shared object files can be found in target-specific directories under `jniLibs` where the JNI can find them.
@@ -720,21 +723,14 @@ See the `cargo-ndk` [README](https://crates.io/crates/cargo-ndk) for other optio
720
723
After this you can build it with `gradlew`:
721
724
722
725
```sh
726
+
cd ./android
723
727
./gradlew build
724
728
```
725
729
726
730
Or build it with Android Studio.
727
731
728
732
Then you can test it in your Android project.
729
733
730
-
##### About `libc++_shared.so`
731
-
732
-
Bevy may require `libc++_shared.so` to run on Android, as it is needed by the `oboe` crate, but typically `cargo-ndk` does not copy this file automatically.
733
-
734
-
To include it, you can manually obtain it from NDK source or use a `build.rs` script for automation, as described in the `cargo-ndk`[README](https://github.com/bbqsrc/cargo-ndk?tab=readme-ov-file#linking-against-and-copying-libc_sharedso-into-the-relevant-places-in-the-output-directory).
735
-
736
-
Alternatively, you can modify project files to include it when building an APK. To understand the specific steps taken in this project, please refer to the comments within the project files for detailed instructions(`app/CMakeList.txt`, `app/build.gradle`, `app/src/main/cpp/dummy.cpp`).
In its examples, Bevy targets the minimum Android API that Play Store <!-- markdown-link-check-disable -->
757
-
[requires](https://developer.android.com/distribute/best-practices/develop/target-sdk) to upload and update apps. <!-- markdown-link-check-enable -->
758
-
Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameActivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to `NativeActivity`.
752
+
In its example, Bevy targets the newest stable Android API to be able to benefit from security and performance improvements. The example also specifies Android API 31 as minimum SDK to support older devices which is recommended on [Android Developers](https://developer.android.com/google/play/requirements/target-sdk#why-target).
759
753
760
-
To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this:
754
+
Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameActivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to [`NativeActivity`](https://developer.android.com/reference/android/app/NativeActivity).
755
+
756
+
To use `NativeActivity`, you need to write a custom `MainActivity.kt` using `NativeActivity` and add the `android-native-activity` feature to Bevy in your `Cargo.toml` like this:
761
757
762
758
```toml
763
-
bevy = { version = "0.14", default-features = false, features = ["android-native-activity", ...] }
759
+
bevy = { version = "*", default-features = false, features = ["android-native-activity", <...>] }
764
760
```
765
761
766
762
Then build it as the [Build & Run](#build--run) section stated above.
767
763
768
-
##### About `cargo-apk`
769
-
770
-
You can also build an APK with `cargo-apk`, a simpler and deprecated tool which doesn't support `GameActivity`. If you want to use this, there is a [folder](./mobile/android_basic) inside the mobile example with instructions.
771
-
772
-
Example | File | Description
773
-
--- | --- | ---
774
-
`android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
0 commit comments