From 4acfd2d59cae2d5f1e359ff42c67fd3f0ee6ae06 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 17 Mar 2026 10:11:21 +0000 Subject: [PATCH] Import android-games-sdk changes for 4.0.0 This imports the SDK from commit 090732c3ca7d8b47ed39e028081d685e4097db7f, from: https://github.com/rust-mobile/android-games-sdk/commits/android-activity-4.0.0 This imports a patch to revert the recent addition of a `_rust_glue_on_create_hook` in favour of fixing the Rust wrapper for `GameActivity_onCreate` which is more consistent with the `ANativeActivity_onCreate` entrypoint that we have in the `native-activity` backend. This also: - Fixes a related rerun-if-changed path in build.rs - Removes the reference to _rust_glue_on_create_hook src/game_activity/mod.rs --- .../game-activity/include/game-activity/GameActivity.h | 2 +- .../native_app_glue/android_native_app_glue.h | 10 ---------- .../game-activity/src/game-activity/GameActivity.cpp | 2 +- .../native_app_glue/android_native_app_glue.c | 9 +++------ android-activity/build.rs | 7 +++++-- android-activity/src/game_activity/ffi_aarch64.rs | 8 ++------ android-activity/src/game_activity/ffi_arm.rs | 8 ++------ android-activity/src/game_activity/ffi_i686.rs | 8 ++------ android-activity/src/game_activity/ffi_x86_64.rs | 8 ++------ android-activity/src/game_activity/mod.rs | 7 ------- 10 files changed, 18 insertions(+), 51 deletions(-) diff --git a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h index b6ff8b4..42f450a 100644 --- a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h +++ b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/GameActivity.h @@ -322,7 +322,7 @@ typedef void GameActivity_createFunc(GameActivity* activity, void* savedState, * "android.app.func_name" string meta-data in your manifest to use a different * function. */ -extern GameActivity_createFunc GameActivity_onCreate_C; +extern GameActivity_createFunc GameActivity_onCreate; /** * Finish the given activity. Its finish() method will be called, causing it diff --git a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.h b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.h index 3cabe73..6029bc9 100644 --- a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.h +++ b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/include/game-activity/native_app_glue/android_native_app_glue.h @@ -514,16 +514,6 @@ void android_app_clear_motion_events(struct android_input_buffer* inputBuffer); */ void android_app_clear_key_events(struct android_input_buffer* inputBuffer); -/** - * A hook that is called within Activity.onCreate, before the android_main - * thread has been spawned. - * - * This gives the Rust glue code a chance to perform any necessary - * initialization that needs to run from the Java main/UI thread, before the - * android_main thread is started. - */ -extern void _rust_glue_on_create_hook(struct android_app* app); - /** * This is a springboard into the Rust glue layer that wraps calling the * main entry for the app itself. diff --git a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/GameActivity.cpp b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/GameActivity.cpp index a178793..045dbdf 100644 --- a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/GameActivity.cpp +++ b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/GameActivity.cpp @@ -538,7 +538,7 @@ static jlong initializeNativeCode_native( // read configuration for the first time readConfigurationValues(code, javaConfig); - GameActivity_onCreate_C(code, rawSavedState, rawSavedSize); + GameActivity_onCreate(code, rawSavedState, rawSavedSize); code->gameTextInput = GameTextInput_init(env, 0); GameTextInput_setEventCallback(code->gameTextInput, diff --git a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/native_app_glue/android_native_app_glue.c b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/native_app_glue/android_native_app_glue.c index 7fd9d39..988287f 100644 --- a/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/native_app_glue/android_native_app_glue.c +++ b/android-activity/android-games-sdk/game-activity/prefab-src/modules/game-activity/src/game-activity/native_app_glue/android_native_app_glue.c @@ -224,8 +224,6 @@ static void* android_app_entry(void* param) { android_app->cmdPollSource.app = android_app; android_app->cmdPollSource.process = process_cmd; - _rust_glue_on_create_hook(android_app); - ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, &android_app->cmdPollSource); @@ -756,10 +754,9 @@ static bool onEditorAction(GameActivity* activity, int action) { return true; } -// XXX: This symbol is renamed with a _C suffix and then re-exported from -// Rust because Rust/Cargo don't give us a way to directly export symbols -// from C/C++ code: https://github.com/rust-lang/rfcs/issues/2771 -// +// XXX: This symbol is renamed with a _C suffix so we can implement +// `GameActivity_onCreate` as a wrapper in Rust that does some additional setup +// before calling this function, JNIEXPORT void GameActivity_onCreate_C(GameActivity* activity, void* savedState, size_t savedStateSize) { diff --git a/android-activity/build.rs b/android-activity/build.rs index 94e44b5..a4969bc 100644 --- a/android-activity/build.rs +++ b/android-activity/build.rs @@ -9,7 +9,11 @@ fn build_glue_for_game_activity() { format!("{android_games_sdk}/game-text-input/prefab-src/modules/game-text-input/{src_inc}/game-text-input/{name}") }; - for f in ["GameActivity.cpp", "GameActivityEvents.cpp"] { + for f in [ + "GameActivity.cpp", + "GameActivityEvents.cpp", + "GameActivityEvents_internal.h", + ] { println!("cargo:rerun-if-changed={}", activity_path("src", f)); } @@ -17,7 +21,6 @@ fn build_glue_for_game_activity() { "GameActivity.h", "GameActivityEvents.h", "GameActivityLog.h", - "GameActivityEvents_internal.h", ] { println!("cargo:rerun-if-changed={}", activity_path("include", f)); } diff --git a/android-activity/src/game_activity/ffi_aarch64.rs b/android-activity/src/game_activity/ffi_aarch64.rs index a755087..323af26 100644 --- a/android-activity/src/game_activity/ffi_aarch64.rs +++ b/android-activity/src/game_activity/ffi_aarch64.rs @@ -38,8 +38,8 @@ pub const __ANDROID_API_V__: u32 = 35; pub const __ANDROID_NDK__: u32 = 1; pub const __NDK_MAJOR__: u32 = 29; pub const __NDK_MINOR__: u32 = 0; -pub const __NDK_BETA__: u32 = 4; -pub const __NDK_BUILD__: u32 = 14033849; +pub const __NDK_BETA__: u32 = 0; +pub const __NDK_BUILD__: u32 = 14206865; pub const __NDK_CANARY__: u32 = 0; pub const WCHAR_MIN: u8 = 0u8; pub const INT8_MIN: i32 = -128; @@ -4854,10 +4854,6 @@ unsafe extern "C" { #[doc = " Clear the array of key events that were waiting to be handled, and release\n each of them.\n\n This method should be called after you have processed the key up events in\n your game loop. You should handle events at each iteration of your game loop."] pub fn android_app_clear_key_events(inputBuffer: *mut android_input_buffer); } -unsafe extern "C" { - #[doc = " A hook that is called within Activity.onCreate, before the android_main\n thread has been spawned.\n\n This gives the Rust glue code a chance to perform any necessary\n initialization that needs to run from the Java main/UI thread, before the\n android_main thread is started."] - pub fn _rust_glue_on_create_hook(app: *mut android_app); -} unsafe extern "C" { #[doc = " This is a springboard into the Rust glue layer that wraps calling the\n main entry for the app itself."] pub fn _rust_glue_entry(app: *mut android_app); diff --git a/android-activity/src/game_activity/ffi_arm.rs b/android-activity/src/game_activity/ffi_arm.rs index f3b28a9..7912674 100644 --- a/android-activity/src/game_activity/ffi_arm.rs +++ b/android-activity/src/game_activity/ffi_arm.rs @@ -165,8 +165,8 @@ pub const __ANDROID_API_V__: u32 = 35; pub const __ANDROID_NDK__: u32 = 1; pub const __NDK_MAJOR__: u32 = 29; pub const __NDK_MINOR__: u32 = 0; -pub const __NDK_BETA__: u32 = 4; -pub const __NDK_BUILD__: u32 = 14033849; +pub const __NDK_BETA__: u32 = 0; +pub const __NDK_BUILD__: u32 = 14206865; pub const __NDK_CANARY__: u32 = 0; pub const WCHAR_MIN: u8 = 0u8; pub const INT8_MIN: i32 = -128; @@ -5266,10 +5266,6 @@ unsafe extern "C" { #[doc = " Clear the array of key events that were waiting to be handled, and release\n each of them.\n\n This method should be called after you have processed the key up events in\n your game loop. You should handle events at each iteration of your game loop."] pub fn android_app_clear_key_events(inputBuffer: *mut android_input_buffer); } -unsafe extern "C" { - #[doc = " A hook that is called within Activity.onCreate, before the android_main\n thread has been spawned.\n\n This gives the Rust glue code a chance to perform any necessary\n initialization that needs to run from the Java main/UI thread, before the\n android_main thread is started."] - pub fn _rust_glue_on_create_hook(app: *mut android_app); -} unsafe extern "C" { #[doc = " This is a springboard into the Rust glue layer that wraps calling the\n main entry for the app itself."] pub fn _rust_glue_entry(app: *mut android_app); diff --git a/android-activity/src/game_activity/ffi_i686.rs b/android-activity/src/game_activity/ffi_i686.rs index 7ead1e9..52ac4e4 100644 --- a/android-activity/src/game_activity/ffi_i686.rs +++ b/android-activity/src/game_activity/ffi_i686.rs @@ -28,8 +28,8 @@ pub const __ANDROID_API_V__: u32 = 35; pub const __ANDROID_NDK__: u32 = 1; pub const __NDK_MAJOR__: u32 = 29; pub const __NDK_MINOR__: u32 = 0; -pub const __NDK_BETA__: u32 = 4; -pub const __NDK_BUILD__: u32 = 14033849; +pub const __NDK_BETA__: u32 = 0; +pub const __NDK_BUILD__: u32 = 14206865; pub const __NDK_CANARY__: u32 = 0; pub const INT8_MIN: i32 = -128; pub const INT8_MAX: u32 = 127; @@ -5306,10 +5306,6 @@ unsafe extern "C" { #[doc = " Clear the array of key events that were waiting to be handled, and release\n each of them.\n\n This method should be called after you have processed the key up events in\n your game loop. You should handle events at each iteration of your game loop."] pub fn android_app_clear_key_events(inputBuffer: *mut android_input_buffer); } -unsafe extern "C" { - #[doc = " A hook that is called within Activity.onCreate, before the android_main\n thread has been spawned.\n\n This gives the Rust glue code a chance to perform any necessary\n initialization that needs to run from the Java main/UI thread, before the\n android_main thread is started."] - pub fn _rust_glue_on_create_hook(app: *mut android_app); -} unsafe extern "C" { #[doc = " This is a springboard into the Rust glue layer that wraps calling the\n main entry for the app itself."] pub fn _rust_glue_entry(app: *mut android_app); diff --git a/android-activity/src/game_activity/ffi_x86_64.rs b/android-activity/src/game_activity/ffi_x86_64.rs index 7224c26..849863f 100644 --- a/android-activity/src/game_activity/ffi_x86_64.rs +++ b/android-activity/src/game_activity/ffi_x86_64.rs @@ -28,8 +28,8 @@ pub const __ANDROID_API_V__: u32 = 35; pub const __ANDROID_NDK__: u32 = 1; pub const __NDK_MAJOR__: u32 = 29; pub const __NDK_MINOR__: u32 = 0; -pub const __NDK_BETA__: u32 = 4; -pub const __NDK_BUILD__: u32 = 14033849; +pub const __NDK_BETA__: u32 = 0; +pub const __NDK_BUILD__: u32 = 14206865; pub const __NDK_CANARY__: u32 = 0; pub const INT8_MIN: i32 = -128; pub const INT8_MAX: u32 = 127; @@ -5335,10 +5335,6 @@ unsafe extern "C" { #[doc = " Clear the array of key events that were waiting to be handled, and release\n each of them.\n\n This method should be called after you have processed the key up events in\n your game loop. You should handle events at each iteration of your game loop."] pub fn android_app_clear_key_events(inputBuffer: *mut android_input_buffer); } -unsafe extern "C" { - #[doc = " A hook that is called within Activity.onCreate, before the android_main\n thread has been spawned.\n\n This gives the Rust glue code a chance to perform any necessary\n initialization that needs to run from the Java main/UI thread, before the\n android_main thread is started."] - pub fn _rust_glue_on_create_hook(app: *mut android_app); -} unsafe extern "C" { #[doc = " This is a springboard into the Rust glue layer that wraps calling the\n main entry for the app itself."] pub fn _rust_glue_entry(app: *mut android_app); diff --git a/android-activity/src/game_activity/mod.rs b/android-activity/src/game_activity/mod.rs index 1f3f150..d0325d4 100644 --- a/android-activity/src/game_activity/mod.rs +++ b/android-activity/src/game_activity/mod.rs @@ -1156,13 +1156,6 @@ extern "Rust" { pub fn android_main(app: AndroidApp); } -// This is called via `GameActivity.onCreate`, from the Java main/UI thread, -// before spawning an `android_main` thread. -#[no_mangle] -pub unsafe extern "C" fn _rust_glue_on_create_hook(_game_activity_glue: *mut ffi::android_app) { - // Noop currently -} - // This is a spring board between android_native_app_glue and the user's // `android_main` function. This is run on a dedicated thread spawned // by android_native_app_glue.