Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.reflect.InvocationTargetException while doing in app update

I have integrated the in-app updates feature by Google Play Core library using this link.

I am using immediate update option because we make various critical bug fixes regularly which are important to update.

Here are the cases when app doesn't crash and updates app successfully and when it crashes.

  1. Click 'Update' button when app update is available and let the update to finish properly without interrupting it in between - App Updated successfully.
  2. Click 'Update' button, update starts to download, but user cancels update in middle by pressing 'x' button present after 'Update Download progress bar' - App Update canceled.
  3. Try opening app again, it crashes with following error.

Fatal Exception: java.lang.RuntimeException java.lang.reflect.InvocationTargetException com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:586) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942) Caused by java.lang.reflect.InvocationTargetException java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942) Caused by android.content.IntentSender$SendIntentException android.app.Activity.startIntentSenderForResultInner (Activity.java:5019) com.google.android.play.core.appupdate.b.startUpdateFlowForResult (Unknown Source:5) co.behtarinternal.app.menu.MenuActivity$checkForAppUpdate$1.onSuccess (MenuActivity.kt:239) co.behtarinternal.app.menu.MenuActivity$checkForAppUpdate$1.onSuccess (MenuActivity.kt:43) com.google.android.play.core.tasks.e.run (Unknown Source:27) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:942)

I have also referred to this question and its answer, but cannot understand how this solution can be implemented.

I have searched a lot everywhere, but didn't find any feasible solution related to this problem.

If any of you out there have faced a similar issue, and your solution worked, do help me.

like image 377
Divya Gupta Avatar asked Dec 24 '19 10:12

Divya Gupta


People also ask

How do I fix Java Lang reflect InvocationTargetException in Java?

Since the InvocationTargetException is caused by another exception thrown by the invoked method, the underlying exception can be found using the getCause() method. Therefore, resolving the InvocationTargetException error equates to finding the actual exception and resolving it.

What could cause Java Lang reflect InvocationTargetException?

What Causes InvocationTargetException. The InvocationTargetException occurs mainly when working with the Java reflection API to invoke a method or constructor, which throws an exception.

What is InvocationTargetException selenium?

The InvocationTargetException is a checked exception that holds an exception thrown by an invoked method or constructor. Since JDK 1.4, this exception has been retrofitted to conform to the general-purpose exception-chaining mechanism.

How do you catch InvocationTargetException?

GenericEJBObject ; maybe it swallows the exception. Alternatively, start the app in debug mode and set a break point in all the constructors of InvocationTargetException . Note: This might turn out to be impractical because other code causes a ton of these exceptions long before you get to the place you want to debug.


1 Answers

From what I have understand, you are trying to use the same instance of the AppUpdateInfo somewhere, where its Intent is a rather PendingIntent that you are trying to use multiple times. Since a PendingIntent can be used only once, it throws the exception. To solve this I am guessing you have an option.

If you are able to reproduce this bug locally, call startUpdateFlowForResult() in a try-catch method and try to catch IntentSender$SendIntentException, or InvocationTargetException. If the exception is catched, that means the PendingIntent is used already. Assuming that your checkUpdates() method can be used recursively, call checkUpdates() again, which should create a new AppUpdateManager instance and start the lifecycle again, which will result in a new, fresh AppUpdateInfo as a result, hence the new PendingIntent that should let you open the app update popup again.

Edit: I'm not sure but what happens when onResume code executes again? Like, checkForUpdates is called but you are also replacing the mAppUpdateManager in onResume call, by calling AppUpdateManager.getInstance(this). So, it is a possibility that the mAppUpdateManager.appUpdateInfo might not belong to the newly assigned mAppUpdateManager in onResume, since on application startup both onCreate and onResume is called. Hence, the object itself may not belong to the AppUpdateManager itself.

A solution might be using two different managers, however I think the mechanism itself will return a singleton which makes them both same (maybe?) anyway, you need to check the address endpoints while in debug mode. The debug object should look like AppUpdateManager@2b62aa, check if the managers are different or not. If they become different as I predict, your problem should be resolved.

like image 200
Furkan Yurdakul Avatar answered Nov 11 '22 05:11

Furkan Yurdakul