Skip to content

examples: Use single up-to-date android example#23491

Open
leomeinel wants to merge 8 commits intobevyengine:mainfrom
leomeinel:android-example
Open

examples: Use single up-to-date android example#23491
leomeinel wants to merge 8 commits intobevyengine:mainfrom
leomeinel:android-example

Conversation

@leomeinel
Copy link
Copy Markdown
Contributor

@leomeinel leomeinel commented Mar 24, 2026

Objective

  • Only use a single modern and better documented android example

Problems with current examples

  • We are currently using deprecated functions like for example setSystemUiVisibility(int).
  • Most Android dependencies are very out of date.
  • Kotlin is the preffered language 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.

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/android-res/mipmap-mdpi/ic_launcher.png to /examples/mobile/android/app/src/main/res/mipmap/ic_launcher.png because that is where it is located by default.
  • Use targetSdk = 36 and compileSdk = 36 and explain in examples/README.md

Testing

This currently builds successfully with cargo-ndk with the following commands:

cd ./examples/mobile
cargo ndk build -t aarch64-linux-android -o ./android/app/src/main/jniLibs

Afterwards you can build it with gradle like this or just use Android Studio:

cd ./android
./gradlew build

Current problems

Unrelated regression

Regression from #23551

Crashes if built without --release flag on x86_64. This seems to be only related to the change in android-activity version.

I have added a note to README.md for this.

Related


@kfc35 kfc35 added C-Examples An addition or correction to our examples O-Android Specific to the Android mobile operating system labels Mar 24, 2026
leomeinel

This comment was marked as resolved.

@leomeinel

This comment was marked as resolved.

@leomeinel

This comment was marked as resolved.

@leomeinel leomeinel changed the title examples: Use single updated android example examples: Use single up-to-date android example Mar 24, 2026
@leomeinel leomeinel force-pushed the android-example branch 3 times, most recently from 3ee40f5 to 9ad8fb2 Compare March 24, 2026 20:20
@leomeinel

This comment was marked as resolved.

@leomeinel leomeinel marked this pull request as ready for review March 24, 2026 20:52
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Domain-Expert Requires deep knowledge in a given domain labels Mar 24, 2026
@leomeinel

This comment was marked as resolved.

leomeinel

This comment was marked as resolved.

@leomeinel

This comment was marked as resolved.

@leomeinel

This comment was marked as off-topic.

@leomeinel

This comment was marked as resolved.

@Litttlefish
Copy link
Copy Markdown
Contributor

Litttlefish commented Mar 26, 2026

glad to see updates on android!

I just followed the java one before when I was making that update though, I'm favor to kotlin too

for libc++_shared, iirc it's required for oboe crate instead of rodio

also about --link-libcxx-shared flag, I think this doesn't work well with bevy, only the trick in the current example worked

@leomeinel

This comment was marked as resolved.

@beicause
Copy link
Copy Markdown
Contributor

I believe --link-libcxx-shared is not needed. See #23548.


- name: Build app for Android
run: cd examples/mobile/android_example && chmod +x gradlew && ./gradlew build
run: cd ./examples/mobile/android && chmod +x ./gradlew && ./gradlew build
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: chmod +x is not needed. I can confirm the permissions of gradlew file you commited is 755 on linux.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. I'll add a fixup commit that omits it. I just forgot to not include it 👍

If anyone wants the file to have 644 permissions instead, I can alternatively just do that.

@leomeinel

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

@leomeinel leomeinel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in Android studio emulator and working.

@mockersf
Copy link
Copy Markdown
Member

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.

I don't agree with this. The differences between examples are meaningful and should be shown somewhere. I would prefer better documentation than just removing them

@mockersf mockersf removed the X-Uncontroversial This work is generally agreed upon label Mar 28, 2026
@leomeinel
Copy link
Copy Markdown
Contributor Author

I don't agree with this. The differences between examples are meaningful and should be shown somewhere. I would prefer better documentation than just removing them

I could add a diff of MainActivity.kt to the readme, would that be okay with you?

@leomeinel
Copy link
Copy Markdown
Contributor Author

Both regressions are now unrelated to this.

Copy link
Copy Markdown
Contributor

@beicause beicause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good cleanup and tend to keep only one example (the native activity example is almost a duplicate). Actually I've never tested the other two examples. For users who want to try other approaches, android-activity and cargo-apk repositories have some examples, too. They might be worth mentioning but we lack testing.

Additionally, this PR will resolve the 16kb compatibility issue (See the screenshots of Android 16.0 / Samsung Galaxy S26 in https://bevyengine.github.io/bevy-example-runner). Already fixed since rodio update?

Objective

- Only use a single modern and better documented android example
- Fix bevyengine#10945
- Fix bevyengine#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 bevyengine#10945 is fixed by migrating to `games-activity` 4. Before this PR, we were using `games-activity` 2. bevyengine#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`
I assumed at first that the table was under the About `cargo-apk` heading for Android, therefore I removed it at first. Now I moved it directly under the Android heading which makes a lot more sense in my opinion. The same has been done with the ios table for consistency.

Additionally this uses mobile as the example identifier since the mentioned file is not platform specific in the table.
@leomeinel leomeinel force-pushed the android-example branch 2 times, most recently from 1cee23a to f85deb5 Compare March 28, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Examples An addition or correction to our examples D-Domain-Expert Requires deep knowledge in a given domain D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes O-Android Specific to the Android mobile operating system S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants