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
+
**⚠️ Note:** If you are using `bevy_audio`the minimum supported Android API version is 26 (Android 8/Oreo).
156
+
157
+
In its example, Bevy uses Android API 36 as `targetSdk` to be able to benefit from security and performance improvements. For backwards compatibility, the example specifies Android API 31 as `minSdk`. This approach is recommended in the [Android Developers documentation](https://developer.android.com/google/play/requirements/target-sdk#why-target).
162
158
163
-
Keep in mind that if you are using `bevy_audio` the minimum supported Android API version is 26 (Android 8/Oreo).
159
+
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 31 and higher, so if you want to use an older API, you need to switch to [`NativeActivity`](https://developer.android.com/reference/android/app/NativeActivity).
164
160
165
-
To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this:
161
+
To use `NativeActivity`, you need to write a custom `MainActivity.kt` using `NativeActivity` instead of `GameActivity`and add the `android-native-activity` feature to Bevy in your `Cargo.toml` like this:
166
162
167
163
```toml
168
-
bevy = { version = "0.19", default-features = false, features = ["android-native-activity", ...] }
164
+
bevy = { version = "0.19", default-features = false, features = ["android-native-activity", <...>] }
169
165
```
170
166
171
-
Then build it as the [Build & Run](#build--run) section stated above.
172
-
173
-
##### About `cargo-apk`
174
-
175
-
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.
176
-
177
-
Example | File | Description
178
-
--- | --- | ---
179
-
`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.
@@ -721,21 +724,14 @@ See the `cargo-ndk` [README](https://crates.io/crates/cargo-ndk) for other optio
721
724
After this you can build it with `gradlew`:
722
725
723
726
```sh
727
+
cd ./android
724
728
./gradlew build
725
729
```
726
730
727
731
Or build it with Android Studio.
728
732
729
733
Then you can test it in your Android project.
730
734
731
-
##### About `libc++_shared.so`
732
-
733
-
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.
734
-
735
-
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).
736
-
737
-
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 -->
758
-
[requires](https://developer.android.com/distribute/best-practices/develop/target-sdk) to upload and update apps. <!-- markdown-link-check-enable -->
759
-
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`.
753
+
**⚠️ Note:** If you are using `bevy_audio`the minimum supported Android API version is 26 (Android 8/Oreo).
754
+
755
+
In its example, Bevy uses Android API 36 as `targetSdk` to be able to benefit from security and performance improvements. For backwards compatibility, the example specifies Android API 31 as `minSdk`. This approach is recommended in the [Android Developers documentation](https://developer.android.com/google/play/requirements/target-sdk#why-target).
760
756
761
-
Keep in mind that if you are using `bevy_audio` the minimum supported Android API version is 26 (Android 8/Oreo).
757
+
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 31 and higher, so if you want to use an older API, you need to switch to [`NativeActivity`](https://developer.android.com/reference/android/app/NativeActivity).
762
758
763
-
To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this:
759
+
To use `NativeActivity`, you need to write a custom `MainActivity.kt` using `NativeActivity` instead of `GameActivity` and add the `android-native-activity` feature to Bevy in your `Cargo.toml` like this:
764
760
765
761
```toml
766
-
bevy = { version = "0.19", default-features = false, features = ["android-native-activity", ...] }
762
+
bevy = { version = "0.19", default-features = false, features = ["android-native-activity", <...>] }
767
763
```
768
764
769
-
Then build it as the [Build & Run](#build--run) section stated above.
770
-
771
-
##### About `cargo-apk`
772
-
773
-
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.
774
-
775
-
Example | File | Description
776
-
--- | --- | ---
777
-
`android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
0 commit comments