我正在使用 Android Studio 开发一个 android-library 项目,该项目使用 google-play-services 来利用 Geofences API。
为了包含 Play 服务,我使用了 maven(gradle.build 文件中的构建规则),就像官方 Android 文档显示的那样(http://developer.android.com/google/play-services/setup.html#Setup)。在这个 android-library 中,我GooglePlayServicesUtil.isGooglePlayServicesAvailable
在实例化LocationClient
.
Log.d(TAG, "Registering geofences");
try{
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) != ConnectionResult.SUCCESS){
Log.e(TAG, "Google Play Services unavailable");
return;
}else
Log.d(TAG, "Google Play Services are available");
Log.d(TAG, "creating LocationClient");
locationClient = new LocationClient(context, this, this);
Log.d(TAG, "connecting LocationClient");
locationClient.connect();
} catch (Exception e) {
e.printStackTrace();
}
这是我从 Logcat 获得的日志:
04-11 09:45:27.331 23741-23781/foo.bar.myoldapp D/AWRLocationService﹕ Registering geofences
04-11 09:45:27.331 23741-23781/foo.bar.myoldapp W/dalvikvm﹕ VFY: unable to resolve static field 3086 (common_google_play_services_install_title) in Lcom/google/android/gms/R$string;
04-11 09:45:27.331 23741-23781/foo.bar.myoldapp D/dalvikvm﹕ VFY: replacing opcode 0x60 at 0x004b
{... and around 20 similar lines ...}
04-11 09:45:27.341 23741-23781/foo.bar.myoldapp E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
04-11 09:45:27.351 23741-23781/foo.bar.myoldapp D/AWRLocationService﹕ Google Play Services are available
04-11 09:45:27.351 23741-23781/foo.bar.myoldapp D/AWRGeofencesReceiver﹕ creating LocationClient
04-11 09:45:27.351 23741-23781/foo.bar.myoldapp W/dalvikvm﹕ VFY: unable to resolve static field 3100 (location_client_powered_by_google) in Lcom/google/android/gms/R$string;
04-11 09:45:27.351 23741-23781/foo.bar.myoldapp D/dalvikvm﹕ VFY: replacing opcode 0x60 at 0x0019
04-11 09:45:30.731 23741-23741/foo.bar.myoldapp D/AWRWifiScanResultBroadcastReceiver﹕ onReceive
如您所见,Google Play 服务似乎没有完全包含在内,原因我不知道(因为我按照 Google 要求的方式包含它们)。但它们似乎存在,因为GooglePlayServicesUtil.isGooglePlayServicesAvailable
返回 true。然后,我实例化 LocationClient 并没有任何反应。没有抛出异常,也没有显示错误日志。我做错了什么?