问题
I am attempting to follow Google's instructions on how to add the new Google Sign-In (not the old Google+ Sign-In) to my Xamarin.Android app. For the life of me, I cannot find the correct Google Play Services NuGet package or Xamarin component that supports the new sign-in system.
When I add the following code to the activity, I get "The type or namespace 'GoogleSignInOptions' could not be found. Are you missing an assembly reference?" build error.
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
Here are the Xamarin.GooglePlayServices NuGet packages that are include in the project:
<package id="Xamarin.GooglePlayServices.Ads" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Analytics" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.AppIndexing" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Base" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Basement" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Identity" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Location" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Maps" version="27.0.0.0" targetFramework="MonoAndroid50" />
<package id="Xamarin.GooglePlayServices.Plus" version="27.0.0.0" targetFramework="MonoAndroid50" />
Is the new Google Sign-In system not yet supported on Xamarin or am I missing something?
回答1:
Enable pre-release nugets and search for:
Xamarin.GooglePlayServices.Identity 29.0.0-beta1
packages.config:
<packages>
<package id="Xamarin.Android.Support.v4" version="23.1.1.0" targetFramework="MonoAndroid44" />
<package id="Xamarin.GooglePlayServices.Auth" version="29.0.0-beta1" targetFramework="MonoAndroid44" />
<package id="Xamarin.GooglePlayServices.Base" version="29.0.0-beta1" targetFramework="MonoAndroid44" />
<package id="Xamarin.GooglePlayServices.Basement" version="29.0.0-beta1" targetFramework="MonoAndroid44" />
<package id="Xamarin.GooglePlayServices.Identity" version="29.0.0-beta1" targetFramework="MonoAndroid44" />
</packages>
C# version of Integrating Google Sign-In into Your Android App
SignInButton button = FindViewById<SignInButton> (Resource.Id.sign_in_button);
gso = new GoogleSignInOptions.Builder (GoogleSignInOptions.DefaultSignIn)
.RequestEmail ()
.Build ();
mGoogleApiClient = new GoogleApiClient.Builder (this)
.EnableAutoManage(mLoginFragment, failedHandler)
.AddApi (Auth.GOOGLE_SIGN_IN_API)
.Build ();
button.Click += delegate {
signIn();
};
来源:https://stackoverflow.com/questions/34639015/how-do-you-integrate-the-new-google-sign-in-on-a-xamarin-android-app