Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you integrate the new Google Sign-In on a Xamarin.Android app?

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?

like image 698
wolfprogrammer Avatar asked Jan 06 '16 17:01

wolfprogrammer


People also ask

Is Xamarin being discontinued?

Xamarin support will end on May 1, 2024 for all Xamarin SDKs. Android 13 and Xcode 14 SDKs (iOS and iPadOS 16, macOS 13) will be the final versions Xamarin will target.

Is Xamarin deprecated Android?

Not dead but possibly moribund. In May 2020, Microsoft announced that Xamarin. Forms, a major component of its mobile app development framework, would be deprecated in November 2021 in favour of a new . Net based product called MAUI - Multiform App User Interface.


1 Answers

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();
};
like image 85
SushiHangover Avatar answered Oct 19 '22 05:10

SushiHangover