我有一个Xamarin.Android项目,我想使用Xamarin.Auth包让用户通过Google登录页面进行身份验证。
这是我在MainActivity.cs上的代码
OAuth2Authenticator auth = new OAuth2Authenticator
(
clientId: "client-id.apps.googleusercontent.com",
scope: "",
authorizeUrl: new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"),
// switch for new Native UI API
// true = Android Custom Tabs and/or iOS Safari View Controller
// false = Embedded Browsers used (Android WebView, iOS UIWebView)
// default = false (not using NEW native UI)
isUsingNativeUI: false
);
auth.Completed += (sender, eventArgs) =>
{
// UI presented, so it's up to us to dimiss it on Android
// dismiss Activity with WebView or CustomTabs
this.Finish();
if (eventArgs.IsAuthenticated)
{
// Use eventArgs.Account to do wonderful things
}
else
{
// The user cancelled
}
};
var ui_object = auth.GetUI(this);
StartActivity(ui_object);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
在调用auth.GetUI(this)方法时,我总是以下面的异常结束:
JNIEnv.FindClass(Type) caught unexpected exception: Java.Lang.ClassNotFoundException: md53c585be971e02235139fd1aef11fc0c1.WebAuthenticatorActivity ---> Java.Lang.ClassNotFoundException: Didn't find class "md53c585be971e02235139fd1aef11fc0c1.WebAuthenticatorActivity"
谁能明白为什么会这样做?我试图谷歌它,但看起来我只是一个谁得到这种类型的错误。
我有VS 2017 15.5.2并使用Android 8.0 API 26
答案 0 :(得分:0)
解决!我删除/添加我的nuget包到Xamarin.Auth和PCLCrypto,现在一切正常。应用程序启动时会显示Google登录页面。