Skip to content

import android-games-sdk patches for mainLooper + onCreate hook#230

Merged
rib merged 1 commit intomainfrom
rib/pr/games-sdk-looper-and-on-create-patches
Mar 10, 2026
Merged

import android-games-sdk patches for mainLooper + onCreate hook#230
rib merged 1 commit intomainfrom
rib/pr/games-sdk-looper-and-on-create-patches

Conversation

@rib
Copy link
Member

@rib rib commented Mar 10, 2026

This imports the SDK from commit
30b8bfcc9a12942d1268820e8a83d7643e99ee92, from:
https://github.com/rust-mobile/android-games-sdk/commits/android-activity-4.0.0

this includes these patches:

PATCH: Add mainLooper to android_app

Track the Looper for the Java main/UI thread in the android_app.

This makes it possible to add file descriptors and callbacks to the Java UI Looper from the android_main thread.

This needs to be initialized by the android_native_app_glue before spawning the android_main thread because the looper needs to be discovered via ALooper_forThread while still running on the Java main thread (in the onCreate callback).

PATCH: Enable Rust glue to hook into onCreate

This declares an extern _rust_glue_on_create_hook that is called from GameActivity onCreate native method callback, before the android_main thread is spawned.

This gives Rust code an opportunity to run code and initialize state while still running on the Java main/UI thread.

For example, this could be used to initialize JNI bindings while we can assume that the current thread has an associated ClassLoader that will be able to find application classes.

It may also be a convenient place to make some initial JNI calls into Android SDK APIs that can only be used from the Java main thread.

Updated import-games-sdk.sh to remove symlinks

While updating the SDK the import script has been updated to remove any symlinks which make it difficult to build android-activity from Git on Windows.

Note: the symlinks were redundant based on how the include paths were already configured in build.rs


Tracking the Java main thread Looper via app->mainLooper will enable us to update #198 so that it also supports the GameActivity backend.

The onCreate hook will make it possible to support an (optional) "android_on_create" application entry point that is guaranteed to run on the Java main / UI thread. For example applications may find this convenient for initialization of state that involves using JNI to call SDK APIs that are only usable from the main Java thread. (E.g. re: #169 + #82)

(these will be addressed in follow up PRs though)

This PR initially adds a stub _rust_glue_on_create_hook just to ensure android-activity links with the these imported changes, and this will be update by follow up PRs.

Note: generate-bindings.sh was re-run after importing these SDK changes

This imports the SDK from commit
30b8bfcc9a12942d1268820e8a83d7643e99ee92, from:
https://github.com/rust-mobile/android-games-sdk/commits/android-activity-4.0.0

this includes these patches:

# PATCH: Add mainLooper to android_app

Track the Looper for the Java main/UI thread in the android_app.

This makes it possible to add file descriptors and callbacks to the Java
UI Looper from the android_main thread.

This needs to be initialized by the android_native_app_glue before
spawning the android_main thread because the looper needs to be
discovered via `ALooper_forThread` while still running on the Java main
thread (in the onCreate callback).

# PATCH: Enable Rust glue to hook into onCreate

This declares an extern `_rust_glue_on_create_hook` that is called from
`GameActivity` `onCreate` native method callback, before the
`android_main` thread is spawned.

This gives Rust code an opportunity to run code and initialize state
while still running on the Java main/UI thread.

For example, this could be used to initialize JNI bindings while we can
assume that the current thread has an associated ClassLoader that will
be able to find application classes.

It may also be a convenient place to make some initial JNI calls into
Android SDK APIs that can only be used from the Java main thread.

# Updated import-games-sdk.sh to remove symlinks

While updating the SDK the import script has been updated to remove any
symlinks which make it difficult to build android-activity from Git on
Windows.

Note: the symlinks were redundant based on how the include paths were
already configured in `build.rs`
@rib rib merged commit 0062cfc into main Mar 10, 2026
7 checks passed
@rib rib deleted the rib/pr/games-sdk-looper-and-on-create-patches branch March 10, 2026 21:07
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.

1 participant