Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to GameActivity 4.0.0 #191

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

jb55
Copy link

@jb55 jb55 commented Mar 14, 2025

This updates the game-activity backend to be based on the latest GameActivty 4.0.0 release from Google's AGDK.

To make it easier to manage future updates to new versions of GameActivity the android-activity integration patches are now maintained under a fork of Google's games-sdk repo which can be found here:

https://github.com/rust-mobile/android-games-sdk/tree/android-activity-4.0.0

During development it's possible to build against an external games-sdk repo (as well we re-generate bindings) by setting the ANDROID_GAMES_SDK environment variable to point to a clone of the android-games-sdk repo.

To avoid having downstream developers need to deal with Git submodules, this adds an import-games-sdk.sh script that will copy the prefab-src code from the games-sdk into this repo.

Closes #185

Fixes #188

Fixes #186

@jb55
Copy link
Author

jb55 commented Mar 14, 2025

going to update this to not use submodules, but to use a similar structure so that it maps nicer to the external repo. as per:

It would be nice to have android-game-sdk-rs host on rust-mobile so that I can reference it in the docs in the subdir:

@jb55 jb55 changed the title Update to 4.0.0 agdk and switch to android-games-sdk-rs submodule Update to 4.0.0 agdk and switch to grafted android-games-sdk-rs repo Mar 14, 2025
@jb55 jb55 marked this pull request as draft March 14, 2025 17:52
@jb55 jb55 force-pushed the agdk-submodule branch 2 times, most recently from fc9439c to 89600ed Compare March 14, 2025 18:43
@jb55 jb55 force-pushed the agdk-submodule branch 2 times, most recently from 6ad67f5 to 2f6ca63 Compare March 14, 2025 19:31
@jb55 jb55 marked this pull request as ready for review March 14, 2025 19:31
@jb55 jb55 marked this pull request as draft March 14, 2025 20:55
@rib
Copy link
Member

rib commented Mar 31, 2025

Starting to look this; I pulled this draft PR, re-ran generate-bindings.sh with the latest rust-bindgen (0.71.1) + fixed a few build issues + bumped gradle to 8.4 in examples/agdk-mainloop (just because the java version I have locally (21) isn't compatible with gradle 8.0).

I'm currently hitting a SIGABRT when GameActivity tries to use JNI to register native methods for the com/google/androidgamesdk/GameActivity class.

Backtrace

03-31 15:08:16.441  3596  3596 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-31 15:08:16.441  3596  3596 F DEBUG   : Build fingerprint: 'samsung/o1sxeea/o1s:14/UP1A.231005.007/G991BXXSEGYA2:user/release-keys'
03-31 15:08:16.441  3596  3596 F DEBUG   : Revision: '22'
03-31 15:08:16.441  3596  3596 F DEBUG   : ABI: 'arm64'
03-31 15:08:16.441  3596  3596 F DEBUG   : Processor: '7'
03-31 15:08:16.441  3596  3596 F DEBUG   : Timestamp: 2025-03-31 15:08:16.218315189+0100
03-31 15:08:16.441  3596  3596 F DEBUG   : Process uptime: 2s
03-31 15:08:16.441  3596  3596 F DEBUG   : Cmdline: co.realfit.agdkmainloop
03-31 15:08:16.441  3596  3596 F DEBUG   : pid: 3491, tid: 3491, name: it.agdkmainloop  >>> co.realfit.agdkmainloop <<<
03-31 15:08:16.441  3596  3596 F DEBUG   : uid: 10644
03-31 15:08:16.441  3596  3596 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
03-31 15:08:16.441  3596  3596 F DEBUG   : Abort message: 'RegisterNatives failed for 'com/google/androidgamesdk/GameActivity'; aborting...'
03-31 15:08:16.441  3596  3596 F DEBUG   :     x0  0000000000000000  x1  0000000000000da3  x2  0000000000000006  x3  0000007fe755da30
03-31 15:08:16.441  3596  3596 F DEBUG   :     x4  626f1f3438221f39  x5  626f1f3438221f39  x6  626f1f3438221f39  x7  7f7f7f7f7f7f7f7f
03-31 15:08:16.441  3596  3596 F DEBUG   :     x8  00000000000000f0  x9  0000007e308cc1e8  x10 0000000000000001  x11 0000007e30912230
03-31 15:08:16.441  3596  3596 F DEBUG   :     x12 0000000000003d29  x13 0000000000000000  x14 0000007fe755c820  x15 0000000026762762
03-31 15:08:16.441  3596  3596 F DEBUG   :     x16 0000007e30976d08  x17 0000007e309540f0  x18 0000007e42b0a000  x19 0000000000000da3
03-31 15:08:16.441  3596  3596 F DEBUG   :     x20 0000000000000da3  x21 00000000ffffffff  x22 0000007b2ac0e180  x23 0000007fe755e4d0
03-31 15:08:16.441  3596  3596 F DEBUG   :     x24 0000000000000000  x25 0000007fe755e450  x26 0000000000000007  x27 0000007e2b3864e0
03-31 15:08:16.441  3596  3596 F DEBUG   :     x28 0000007fe755e280  x29 0000007fe755dab0
03-31 15:08:16.441  3596  3596 F DEBUG   :     lr  0000007e30903b8c  sp  0000007fe755da10  pc  0000007e30903bb8  pst 0000000000001000
03-31 15:08:16.441  3596  3596 F DEBUG   : 97 total frames
03-31 15:08:16.441  3596  3596 F DEBUG   : backtrace:
03-31 15:08:16.441  3596  3596 F DEBUG   :       #00 pc 0000000000059bb8  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 2febda0bbcffa4b71545deb95b27767d)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #01 pc 000000000093091c  /apex/com.android.art/lib64/libart.so (art::Runtime::Abort(char const*)+344) (BuildId: c35c9ebf7bb06435e4b31977d87bd5d5)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #02 pc 00000000000160fc  /apex/com.android.art/lib64/libbase.so (android::base::SetAborter(std::__1::function<void (char const*)>&&)::$_0::__invoke(char const*)+80) (BuildId: 1470f61c05962eb04fafe76bd58bf664)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #03 pc 0000000000006ec8  /system/lib64/liblog.so (__android_log_assert+308) (BuildId: d6691282faf3d4423b9ceef9c6ddc654)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #04 pc 00000000000cbf40  /data/app/~~Ld9_34sF6KlGCvUMiBgBYw==/co.realfit.agdkmainloop-qYfflTq1pAm7e1SMhhOrcw==/base.apk (offset 0x2be000)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #05 pc 00000000000cbc38  /data/app/~~Ld9_34sF6KlGCvUMiBgBYw==/co.realfit.agdkmainloop-qYfflTq1pAm7e1SMhhOrcw==/base.apk (offset 0x2be000)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #06 pc 00000000000cbf74  /data/app/~~Ld9_34sF6KlGCvUMiBgBYw==/co.realfit.agdkmainloop-qYfflTq1pAm7e1SMhhOrcw==/base.apk (offset 0x2be000)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #07 pc 00000000000c75e4  /data/app/~~Ld9_34sF6KlGCvUMiBgBYw==/co.realfit.agdkmainloop-qYfflTq1pAm7e1SMhhOrcw==/base.apk (offset 0x2be000) (Java_com_google_androidgamesdk_GameActivity_initializeNativeCode+72)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #08 pc 0000000000383d70  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: c35c9ebf7bb06435e4b31977d87bd5d5)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #09 pc 000000000036d574  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+612) (BuildId: c35c9ebf7bb06435e4b31977d87bd5d5)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #10 pc 0000000000358bc0  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+132) (BuildId: c35c9ebf7bb06435e4b31977d87bd5d5)
03-31 15:08:16.441  3596  3596 F DEBUG   :       #11 pc 0000000000353524  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<true>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, bool, art::JValue*)+448) (BuildId: c35c9ebf7bb06435e4b3
1977d87bd5d5)

It's not a useful backtrace, but apparently it's currently blowing up in RegisterNatives with GameActivity logs like:

03-31 15:40:22.084 18715 18715 I GameActivity: Looking for library libmain.so
03-31 15:40:22.084 18715 18715 I GameActivity: Found library libmain.so. Loading...
03-31 15:40:22.090 18715 18715 D GameActivity: GameActivity_register
03-31 15:40:22.091 18715 18715 V GameActivity: Registering com/google/androidgamesdk/GameActivity's 24 native methods...
03-31 15:40:22.096 18715 18715 F GameActivity: RegisterNatives failed for 'com/google/androidgamesdk/GameActivity'; aborting...

@jb55 In terms of being stuck with generating bindings, I'm not entirely sure what issue you might have hit and I guess I was lucky that I didn't seem to hit an issue here.

@jb55
Copy link
Author

jb55 commented Mar 31, 2025

I think i was hitting this, then i just update games-activity to the correct version on the gradle side?

@rib
Copy link
Member

rib commented Mar 31, 2025

Oh, presumably it's just because the example was pulling in the older 2.0.2 version of GameActivity - I had only skimmed the first few commit messages and got the wrong impression that the current PR just re-worked things in prep for the 4.0 update but didn't have those changes. I'll make sure to pull in GameActivity 4.0 in the example and see how that goes.

@rib
Copy link
Member

rib commented Mar 31, 2025

Ah, yep the initial issues with RegisterNatives was just because the example was pulling in GameActivity 2.0.2.

Now though I do seem to hit a different issue with 4.0.0:

03-31 15:57:02.089 24796 25880 I RustStdoutStderr:
03-31 15:57:02.089 24796 25880 I RustStdoutStderr: thread '<unnamed>' panicked at /home/rib/src/rust-mobile/android-activity/android-activity-git-dev0/android-activity/src/game_activity/mod.rs:392:42:
03-31 15:57:02.089 24796 25880 I RustStdoutStderr: internal error: entered unreachable code

No useful panic backtrace atm, but that's the match for NativeAppGlueAppCmd and it sounds like you were already aware we need to update this from your TODO list.

@rib rib force-pushed the agdk-submodule branch from d37e612 to 2fb16d2 Compare March 31, 2025 23:06
@rib
Copy link
Member

rib commented Mar 31, 2025

I've pushed some follow ups that I think bash this into a state where we can merge.

Since the latest bindgen-cli requires rustc 1.70 this PR also bumps our rust-version from 1.69 to 1.73 (it's bumped a bit further because 1.73 has an Android fix for the stat struct definition).

When generating the bindings, we now pass --rust-target 1.73.0 to avoid generating FFI bindings that require a newer compiler.

I've pushed a couple of extra patches to android-games-sdk that disable these commands:

  • APP_CMD_KEY_EVENT
  • APP_CMD_TOUCH_EVENT
  • APP_CMD_EDITOR_ACTION

The first two should be redundant with android-activity since we already have notifyInput that supports an InputAvailable event for applications.

The EDITOR_ACTION command is initially disabled since we don't currently support forwarding the state to the application but also because I think the state should eventually be exposed to applications as an input event, and it should also rely on notifyInput + InputAvailable.

For future convenience, it's fairly straight-forward now to build against an external games-sdk by setting the ANDROID_GAMES_SDK environment variable, which will be recognised by generate-bindings.sh and build.rs.

So far, I've only tested with examples/agdk-mainloop

@rib rib marked this pull request as ready for review March 31, 2025 23:22
jb55 and others added 11 commits April 1, 2025 15:41
We are going to use a submodule so that it is easier to track and rebase
our local changes onto new versions of android-games-sdk

Signed-off-by: William Casarin <[email protected]>
Also includes our patches on top (branch android-activity-2.0.2). This
is mainly to test to make sure everything is still working. We will
switch to the android-activity-4.0.0 branch when we're done

Signed-off-by: William Casarin <[email protected]>
This replaces `copy-files` + `file_list.txt` (subjective simplification)

This imports the SDK from commit 1b544f896646b29e798c5be0a151a488906797f7, from:
https://github.com/rust-mobile/android-games-sdk/commits/android-activity-4.0.0
Signed-off-by: William Casarin <[email protected]>
For convenience, when updating to new GameActivity versions, this makes
it possible to build against the out-of-tree `android-games-sdk` repo.

This also updates `generate-bindings.sh` to point at $ANDROID_GAMES_SDK
if set.

E.g.

```
git clone [email protected]:rust-mobile/android-games-sdk.git \
    --branch android-activity-4.0.0
export ANDROID_GAMES_SDK=$PWD/android-games-sdk

./generate-bindings.sh
cargo build --features=game-activity --target=aarch64-linux-android
```
@rib rib force-pushed the agdk-submodule branch from 2fb16d2 to c0f3fa6 Compare April 1, 2025 14:46
@rib
Copy link
Member

rib commented Apr 1, 2025

For reference, I'm going to look at updating some of the rust-android-examples so I can smoke test this a bit more.

@jb55 maybe you can smoke test this updated branch if you get a moment and check that it works for your needs

@rib rib requested a review from MarijnS95 April 1, 2025 15:23
@jb55
Copy link
Author

jb55 commented Apr 2, 2025

@rib yup i will try soon

@rib
Copy link
Member

rib commented Apr 2, 2025

When I went to test against agdk-egui and agdk-eframe I was reminded of how much of chore it can be to deal with patching winit and the examples to test.

An issue I've hit is that #163 was a breaking change that makes android-activity incompatible with winit 0.30.x which is awkward.

It's made me worried about the decision to swap in the ndk input types.

@jb55
Copy link
Author

jb55 commented Apr 2, 2025

Oh yeah i have this applied on top of the tagged version in our branch to avoid that issue

@rib
Copy link
Member

rib commented Apr 4, 2025

For reference here I've tested this PR against updated agdk-mainloop, agdk-egui and agdk-eframe examples here: https://github.com/rust-mobile/rust-android-examples/tree/rib/wip/android-activity-0.6.x

To remain compatible with android-activity 0.6.x (and thus winit 0.30 / egui 0.31) I reverted #163 locally

@rib
Copy link
Member

rib commented Apr 4, 2025

Instead of reverting #163 on main, perhaps we can create a v0.6.x branch for android-activity from the commit before #163 was merged and then we would cut a new release from that branch after merging this PR.

Note: even though this PR updates to a new major version of GameActivity we wouldn't consider that a semver breaking change for the android-activity crate itself while it hasn't forced us to break the Rust API.

I.e. it's acceptable that applications currently based on GameActivity 2.0 will have to update their build to pull GameActivity 4.0 when updating to the latest android-activity 0.6.x. This is akin to an MSRV bump (for a downstream application currently tied to an older compiler version) where it's sometimes necessary to address build issues that are out of scope from a crate's Rust API semver.

@rib rib changed the title Update to 4.0.0 agdk and switch to grafted android-games-sdk-rs repo Update to GameActivity 4.0.0 Apr 4, 2025
Update the notes on how to update to new GameActivity releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update GameActivity from v2.0.2 to v4.0.0 GameActivity onTextInputEvent getting called twice
2 participants