I am currently investigating a tricky issue which I am facing with my application. It seems my app (heavily relying on Location, but also using Google Analytics and GCM Task Service) is causing Google Play Services to crash. (Popup appears rather frequently sometimes, but then disappears again for hours - days).
I cannot really track down where the issue is coming from also not how to reproduce it, two things I know:
- It is my app - disabling it, will fix the crashes
- If I disable the location part of my app, the crashes stop.
I managed to grab a stacktrace at some point:
/? 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)
I am requesting Location Updates in a separate process using the PendingIntent way to do so:
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());
}
}
});
Those updates I receive quite successfully here:
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));
}
}
}
Some background (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'
I tried looking up the stack trace and could not find anything relevant. Has anyone ever encountered a similar issue? Any ideas on how I could track down the reason maybe?
Thanks!