google-play-services 8.4.0 - Background crash - android

So I'm running google-play-services:8.4.0, and for quite some users I'm getting the following error. This happens in the background as I have no logs of things happening before, even days before. (I didn't get any crashes on 8.3.0)
Here is the gradle specs :
'com.google.android.gms:play-services-base:8.4.0',
'com.google.android.gms:play-services-maps:8.4.0',
'com.google.android.gms:play-services-appindexing:8.4.0',
'com.google.android.gms:play-services-analytics:8.4.0',
'com.google.android.gms:play-services-gcm:8.4.0'
And the crash log :
java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.android.gms.common.api.ResultCallback.a(com.google.android.gms.common.api.Result)' on a null object reference
at com.google.android.gms.common.api.internal.zzb$zza.b(Unknown Source)
at com.google.android.gms.common.api.internal.zzb$zza.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
As I can't reproduce this bug, anyone has a hint of what is going wrong in there ?

Always disconnect GoogleApiClient in onStop of your activity and reconnect in inStart. This might solve your problem.
#Override
public void onStop() {
mgoogleApiClient.disconnect();
super.onStop();
}
#Override
public void onStart() {
super.onStart();
mgoogleApiClient.connect();
}

Related

Failed to bind to the service

On the app launch, I need to check whether a new version is available on play store or not. To check I have implemented below code in Splash screen.
private void checkNewVersionAvailability() {
appUpdateManager = AppUpdateManagerFactory.create(getApplicationContext());
appUpdateInfo = appUpdateManager.getAppUpdateInfo();
appUpdateInfo.addOnCompleteListener(new OnCompleteListener<AppUpdateInfo>() {
#Override
public void onComplete(Task<AppUpdateInfo> task) {
if (task.isComplete()) {
if (task.getResult().updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
checkVersion(task.getResult());
} else if (task.getResult().updateAvailability() == UpdateAvailability.UPDATE_NOT_AVAILABLE) {
if (StringUtils.isNullOrEmpty(ChevronApplication.deviceId)) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
RegsiterDeviceHandler handler = new RegsiterDeviceHandler(SplashScreen.this);
handler.registerDevice(false);
handler.showNextScreen();
}
}, SLEEP_TIME);
} else {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
new RegsiterDeviceHandler(SplashScreen.this).showNextScreen();
}
}, SLEEP_TIME);
}
}
}
}
});
During testing on the device, I didn't get the issue. These crash logs are I found from the Pre-launch report in Playstore.
> FATAL EXCEPTION: main
Process: com.mac.app, PID: 19641
com.google.android.play.core.tasks.RuntimeExecutionException: com.google.android.play.core.internal.aa: Failed to bind to the service.
at com.google.android.play.core.tasks.k.getResult(Unknown Source)
at com.chevronrenaissance.app.activity.SplashScreen$2.onComplete(SplashScreen.java:113)
at com.google.android.play.core.tasks.a.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5538)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: com.google.android.play.core.internal.aa: Failed to bind to the service.
at com.google.android.play.core.internal.q.b(Unknown Source)
at com.google.android.play.core.internal.q.a(Unknown Source)
at com.google.android.play.core.internal.s.a(Unknown Source)
at com.google.android.play.core.internal.r.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
There seems to be an issue with Google Play Core library with Android Virtual Devices. I had to add a try/catch statement so the Pre-launch testing passes. I think you may have to wrap al your AppUpdateManager calls so the exception is catched.
I was running a very similar issue using the in-app review component. It turned out one of the emulators I was developing with had not been signed into a Google Play account. You may want to ensure your emulator is signed into Google Play.
You can check task.isSuccessful().
In this case, when the task is not successful, you can get the exception use method task.getException()
Most likely that the Emulator you are using do not contain Google Play at all.
If you are running it in a emulator and if emulator is not signed for Google play, it will show the error that "PID: [6084] AppUpdateService : Failed to bind to the service."

I got a super weird crash on Fabric onResume of my FragmentActivity, at the super.onResume()

What does this mean, and can be fixed somehow?
Not crashing in my code, but in the super of the FragmentActivity, I can't figure out what I am doing wrong:
Fatal Exception: java.lang.IllegalArgumentException
at android.os.Parcel.readException(Parcel.java:1688)
at android.os.Parcel.readException(Parcel.java:1637)
at android.app.ActivityManagerProxy.isTopOfTask(ActivityManagerNative.java:5505)
at android.app.Activity.isTopOfTask(Activity.java:5983)
at android.app.Activity.onResume(Activity.java:1253)
at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:485)
at nl.hgrams.passenger.activities.PSTimelineFragmentsActivity.onResume(PSTimelineFragmentsActivity.java:576)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270)
at android.app.Activity.performResume(Activity.java:6788)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:2844)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2858)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1575)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6186)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
This is my onResume():
#Override
protected void onResume() {
super.onResume();
registerReceiver(addedPitstopBroadcastReceiver,
new IntentFilter("addedPitstop"));
if (PSApplicationClass.getInstance().pref.getUserId(PSTimelineFragmentsActivity.this) != null) {
renewSettings();
PSApplicationClass.getInstance().pref.setIsBackground(this, false);
if (PSApplicationClass.getInstance().pref.isRefetchUser(PSTimelineFragmentsActivity.this)) {
PSApplicationClass.getInstance().pref.setRefetchUser(PSTimelineFragmentsActivity.this, false);
MyFirebaseInstanceIDService.changeFirebaseToken(PSTimelineFragmentsActivity.this);
}
}
}
But it directly crashed at onResume, so it didn't pass to the next line. Also tried to reproduce me, but could not.
The user had a: LG G-Pad 8.3

Sinch client wont start?

I am trying to use sinch an i am having erros i dont know why an i seem to have set it well.
and it is pointing me to this part of the code which
public void that(final String name) {
call.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if ((getSinchServiceInterface() == null) || (!getSinchServiceInterface().isStarted())) {
getSinchServiceInterface().startClient(name);
}
}
});
}
the "getSinchServiceInterface().startClient(name);"
this is my error
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.obi.thinker.logins.call.SinchService$SinchServiceInterface.startClient(java.lang.String)' on a null object reference
at com.obi.thinker.logins.tabs.Chatting$caller$1.onClick(Chatting.java:386)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5683)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
I dont understand
if ((getSinchServiceInterface() != null && !getSinchServiceInterface().isStarted())) {
getSinchServiceInterface().startClient(name);
}
the callstack says:
getSinchServiceInterface() is null
And would suggest to read this:
https://stackoverflow.com/a/41477703/1979882
I was facing this issue for weeks. I literally rewrote my SinchService from scratch, removed Sinch altogether and tried starting fresh but all to no avail. It turns out I was simply initialising my call too early.
I recommend you move the code block:
if ((getSinchServiceInterface() != null || !getSinchServiceInterface().isStarted())) {
getSinchServiceInterface().startClient(name);
}
I moved mine to the very end of my onResume method and it seems to all work fine now. The reason this doesn't continually keep starting the client is because we are adding the 'if' statement to make sure it isn't already initialised.
If you find that the issue is still thrown, which was the case for me at one point, try calling it at the very end of the launch of your activity. It simply comes down to being called before your BaseActivity has a chance to initialise mSinchServiceInterface

Android mediaplayer using uri causes app crash

I have been working to resolve this problem for the last three days and cannot get it working. These are the steps of my app:
Open file browser to select and audio file
Audio file is selected
Selected audio file is added to the database
from a list of items the added file is selected
a play button is pressed to play the sound file
at this point the sound file will play, however if I close the app then open it again and attempt to play the same sound file the app crashes with the following error:
FATAL EXCEPTION: main
Process: com.arcitech.developer.ultimatesoundboard, PID: 22967
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
at com.arcitech.developer.ultimatesoundboard.activities.ItemDetailFragment$4.onClick(ItemDetailFragment.java:153)
at android.view.View.performClick(View.java:5156)
at android.view.View$PerformClick.run(View.java:20755)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
the filepath(uri) I am saving to the database is:
Content://com.android.providers.media.documents/document/audio%3A15790
and the code I am using is located in the onCreateView of a fragment:
MediaPlayer m;
playSound.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (m != null) {
m.stop();
m.release();
m = null;
}
m = MediaPlayer.create(getActivity(), Uri.parse(mItem.filePath));
m.start();
m.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer m) {
countdownTimerHandler.removeCallbacks(countdownTimerRunnable);
}
});
}
});
According to the doc for MediaPlayer.create(), it can return null if for some reason MediaPlayer cannot be created. You should be checking the return value for null every time unless you are very confident that it will not return null (but even then, do it for safety).
You may also want to check the log at the time create() is called to see if Android is leaving any clues as to why creation failed.

"GoogleApiClient is not connected yet" exception in Cast application

I'm developing an Android application that casts content to Chromecast.
Sometimes in my com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks implementation in the onConnected method, I get a
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
exception.
Here is the stack trace:
FATAL EXCEPTION: main
Process: com.joaomgcd.autocast, PID: 13771
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
at com.google.android.gms.internal.eg.a(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient.b(Unknown Source)
at com.google.android.gms.cast.Cast$CastApi$a.launchApplication(Unknown Source)
at com.joaomgcd.autocast.media.MediaConnectionCallbacks.onConnected(MediaConnectionCallbacks.java:37)
at com.google.android.gms.internal.dx.b(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient.bn(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient.f(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient$2.onConnected(Unknown Source)
at com.google.android.gms.internal.dx.b(Unknown Source)
at com.google.android.gms.internal.dx.bT(Unknown Source)
at com.google.android.gms.internal.dw$h.b(Unknown Source)
at com.google.android.gms.internal.dw$h.b(Unknown Source)
at com.google.android.gms.internal.dw$b.bR(Unknown Source)
at com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
This only seems to happen if I had already connected to the GoogleApiClient before and am connecting for a second time. Between the 2 calls I disconnect from the api client with the code below.
My guess is that this is a bug. Am I correct? Since I'm in the onConnected method, the GoogleApiClient should already be connected.
What can I do to get around it? Should I just wait for a while until the GoogleApiClient is really connected?
I am doing this in a service and here are the relevant bits:
when the service starts:
mMediaRouter.addCallback(mMediaRouteSelector, mediaCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
mediaCallback has this code:
#Override
public void onRouteAdded(MediaRouter router, RouteInfo route) {
super.onRouteAdded(router, route);
if (route.getDescription().equals("Chromecast")) {
...
mSelectedDevice = com.google.android.gms.cast.CastDevice.getFromBundle(route.getExtras());
...
castClientListener = new CastListener(context, apiClient);
Cast.CastOptions.Builder apiOptionsBuilder = Cast.CastOptions.builder(mSelectedDevice, castClientListener);
...
apiClient.set(new GoogleApiClient.Builder(context).addApi(Cast.API, apiOptionsBuilder.build()).addConnectionCallbacks(connectionCallback).addOnConnectionFailedListener(new MediaConnectionFailedListener(context)).build());
apiClient.get().connect();
}
}
connectionCallback has this code:
#Override
public void onConnected(final Bundle arg0) {
...
Cast.CastApi.launchApplication(apiClient, UtilAutoCast.CHROMECAST_APP_ID, false).setResultCallback(connectionCallback);
...
}
The code above is the part where the crash happens.
And when I stop the service I run this code:
if (mMediaRouter != null) {
mMediaRouter.removeCallback(mediaCallback);
mMediaRouter = null;
}
if (apiClient != null) {
Cast.CastApi.stopApplication(apiClient);
if (apiClient.isConnected()) {
apiClient.disconnect();
apiClient = null;
}
}
Thanks in advance.
Google APIs for Android > GoogleApiClient
You should instantiate a client object in your Activity's onCreate(Bundle) method and then call connect() in onStart() and disconnect() in onStop(), regardless of the state.
The implementation of the GoogleApiClient appears designed for only a single instance. It's best to instantiate it only once in onCreate, then perform connections and disconnections using the single instance.
I would guess that only one GoogleApiClient can be actually be connected, but multiple instances are receiving the onConnected callback.
In your case it's probably fine to not call connect in onStart, but only in onRouteAdded.
I think this issue is very similar to Fatal Exception: java.lang.IllegalStateException GoogleApiClient is not connected yet
Have you declare following <meta> tag
<application ...>
...
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
...
</application>
I just forgot to write so may you also stuck with this reason.
Thank you.
From showcase app (Googlecast Github Sample CastHelloText-android ) receiver app is launched onRouteSelected (not onRouteAdded as you are doing in your code). I would try to change that. In case it does not work, I would add log lines in every method related to connection & session, and see what is happening.
Another tip: I have had crash with stopping the application (in case chromecast device is physically plugged out from power). Solution is to putCast.CastApi.stopApplication(apiClient); inside if (apiClient.isConnected()).
It seems like you are calling GoogleApiClient before it is connected
move this line in onCreate()
// First we need to check availability of play services
if (checkPlayServices()) {
// Building the GoogleApi client
//buildGoogleApiClient();
try {
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}catch (IllegalStateException e)
{
Log.e("IllegalStateException", e.toString());
}
createLocationRequest();
}
Hope it helps you.

Categories

Resources