Skip to content

Conversation

@akghasemi
Copy link

This pull request adds missing Snapshot APIs for Play Games Services V2, which are currently skipped in the Xamarin bindings (see issue #972). Attempts to expose them via Metadata.xml were unsuccessful, as the bindings ignored the relevant classes. I resolved this by manually adding bindings to the Additions folder. These APIs are actively used in my game and confirmed to be working.

Comment on lines +11 to +26
[Register("getSnapshotsClient", "(Landroid/app/Activity;)Lcom/google/android/gms/games/SnapshotsClient;", "")]
public static unsafe global::Android.Gms.Games.SnapshotsClient GetSnapshotsClient(global::Android.App.Activity activity)
{
const string __id = "getSnapshotsClient.(Landroid/app/Activity;)Lcom/google/android/gms/games/SnapshotsClient;";
try
{
JniArgumentValue* __args = stackalloc JniArgumentValue[1];
__args[0] = new JniArgumentValue((activity == null) ? IntPtr.Zero : ((global::Java.Lang.Object)activity).Handle);
var __rm = _members.StaticMethods.InvokeObjectMethod(__id, __args);
return global::Java.Lang.Object.GetObject<global::Android.Gms.Games.SnapshotsClient>(__rm.Handle, JniHandleOwnership.TransferLocalRef)!;
}
finally
{
global::System.GC.KeepAlive(activity);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Were these generated following .NET 10's generated code? or .NET 8/9?

.NET 10 has significate changes here to support NativeAOT.

Ideally, we could somehow make this work in Metadata.xml, as it would not need to be manually updated if we improve the generated code.

Copy link
Author

Choose a reason for hiding this comment

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

this is generated only for .NET 8/9.
I tried different approaches to fix them with metadata.xml file but no luck, it just skips these Apis even if you write metadata.xml correctly, my guess is that there is a bug or limitation with Xamarin binding generator

Copy link
Member

Choose a reason for hiding this comment

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

Does it print out a build warning? That could say why it skips them.

@moljac might have some suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

for exmaple I tried this:
<attr path="/api/package[@name='com.google.android.gms.games.snapshot']/class[@name='Snapshot']" name="visibility" value="public" />
and also this
<interface` path="/api/package[@name='com.google.android.gms.games.snapshot']/interface[@name='Snapshot']" name="Snapshot" managedName="ISnapshot" visibility="public" />

but none of them generated the snapshot class or interface and I didn't see any warning during build process

Copy link
Contributor

Choose a reason for hiding this comment

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

for exmaple I tried this: <attr path="/api/package[@name='com.google.android.gms.games.snapshot']/class[@name='Snapshot']" name="visibility" value="public" />

OK this looks OK.

and also this <interface` path="/api/package[@name='com.google.android.gms.games.snapshot']/interface[@name='Snapshot']" name="Snapshot" managedName="ISnapshot" visibility="public" />

This does not make sense. This looks like api.xml snippet.

but none of them generated the snapshot class or interface and I didn't see any warning during build process

You must turn on all warnings to see what is going on. Yeah it is a bit unpractical, but 99% of those warnings will never (or optimistically not so soon) be fixed.

@moljac
Copy link
Contributor

moljac commented Nov 4, 2025

@akghasemi

Generated code approach is really not recommended, because in future .NET versions tooling could generate different code and this might not work.

It took me few months to clean all up. Historically we had to resort to that workaround, because of bugs in our tooling. Today it should be much much better.

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.

3 participants