我正在尝试按照
Google’s instructions关于如何将新的Google登录(不是旧的Google登录)添加到我的Xamarin.Android应用程序中.对于我的生活,我找不到支持新登录系统的正确的Google Play服务NuGet包或Xamarin组件.
当我将以下代码添加到活动时,我得到“无法找到类型或命名空间’GoogleSignInOptions’.您是否缺少程序集引用?”构建错误.
// 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();
以下是项目中包含的Xamarin.GooglePlayServices NuGet包:
<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" />
解决方法
启用预发布预设并搜索:
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#版本为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(); };