使用Xamarin Google Play服务时如何避免MissingMethodException?

时间:2015-07-20 02:30:33

标签: android xamarin xamarin.android

我使用Xamarin的Google Play服务组件,但似乎在运行时无法找到Android.Runtime.JNIEnv中的方法。

以下是我的用法:

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Gms.Location;
using Android.Gms.Common.Apis;

以下是代码失败的示例:

request = new LocationRequest();
request.SetNumUpdates(1);

导致此异常(调用SetNumUpdates时):

  

System.MissingMethodException:找不到方法:'Android.Runtime.JNIEnv.CallObjectMethod'。

此代码:

request = new LocationRequest();
 client = new GoogleApiClientBuilder(this).AddApi(LocationServices.API).AddConnectionCallbacks(this).AddOnConnectionFailedListener(this).Build();

导致以下异常:

  

System.MissingMethodException:找不到方法:'Android.Runtime.JNIEnv.StartCreateInstance

如何确定可以找到Android.Runtime.JNIEnv中的方法?这很奇怪,因为包含Mono.Android并且intellisense能够找到这些方法。我可以自己找到它们,问题是什么,如何解决?

1 个答案:

答案 0 :(得分:0)

您的模拟器/设备是否安装了Google Play服务?

如果您使用的是真实设备,则会自动安装Google Play服务。

如果您使用Android sdk中的Android模拟器,则必须从Google API图像创建模拟器

enter image description here