我目前正在调查我在申请时遇到的棘手问题。我的应用程序(严重依赖位置,但也使用 Google Analytics 和 GCM任务服务)导致Google Play服务崩溃。 (弹出有时会出现频繁,但随后会再次消失数小时 - 天)。
我无法真正追查问题的来源,也不能找到如何重现它,我知道两件事:
我设法在某个时候抓住 stacktrace :
/? E/AndroidRuntime: FATAL EXCEPTION: lowpool[0]
Process: com.google.android.gms.persistent, PID: 29021
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at aipa.a(:com.google.android.gms:1053)
at ailk.c(:com.google.android.gms:252)
at aill.run(:com.google.android.gms:1047)
at kmo.run(:com.google.android.gms:450)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at kqt.run(:com.google.android.gms:17)
at java.lang.Thread.run(Thread.java:818)
我正在使用PendingIntent方式在单独进程中请求位置更新:
if (mTrackIntent == null) {
Intent trackIntent = LocationHandlerReceiver.create(getApplicationContext());
mTrackIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE_TRACK, trackIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
PendingResult<Status> statusPendingResult = LocationServices.FusedLocationApi.flushLocations(mGoogleApiClient);
statusPendingResult.setResultCallback(result -> {
if (result.isSuccess()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mTrackIntent);
//noinspection MissingPermission
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mTrackIntent);
} else {
if (BuildConfig.DEBUG) {
DebugUtils.showDebugToastOnUiThread(getApplicationContext(), "DEV: Requesting location updates.. failed: " + result.getStatusMessage());
}
}
});
我在这里收到的更新成功:
public static class LocationHandlerReceiver extends BroadcastReceiver {
public static Intent create(Context context) {
Intent trackIntent = new Intent(context, LocationHandlerReceiver.class);
trackIntent.setAction(ACTION_TRACK);
return trackIntent;
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
Log.d(TAG, "Received location intent: \n" + IntentUtil.dumpIntent(intent));
try {
if (LocationAvailability.hasLocationAvailability(intent)) {
LocationAvailability locationAvailability = LocationAvailability.extractLocationAvailability(intent);
Crashlytics.log(Log.INFO, TAG, "Could not process location result, Location unavailable: " + locationAvailability.isLocationAvailable());
} else if (LocationResult.hasResult(intent)) {
// process results
} else {
Crashlytics.logException(new Exception("Could not log location because of null Location"));
}
} catch (Throwable throwable) {
Log.e(TAG, "Could not process location result", throwable);
Crashlytics.logException(new IllegalStateException("Could not process location result", throwable));
}
}
}
一些背景(app - build.gradle):
defaultConfig {
minSdkVersion 16
targetSdkVersion 25 //24
compileSdkVersion 25 //24
}
compile 'com.google.android.gms:play-services-location:9.6.1'
compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.google.android.gms:play-services-places:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
我尝试查找堆栈跟踪,找不到任何相关内容。有没有人遇到类似的问题?关于如何追查原因的任何想法可能?
谢谢!