Crash while self updating APK (component class does not exist)

你。 提交于 2019-12-21 03:37:29

问题


I am working on a system application which updates itslef by downloading an apk and installing it by using PackageManager's installPackage() method.

I am getting the following exception:

Fatal Exception: java.lang.IllegalArgumentException: Component class com.myapp.package.receivers.SomeOldReceiver does not exist in com.myapp.package
           at android.os.Parcel.readException(Parcel.java:1544)
           at android.os.Parcel.readException(Parcel.java:1493)
           at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:3420)
           at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:1492)
           at com.myapp.package.utils.AndroidUtils.enableDisableComponent(SourceFile:113)
           at ...

The "SomeOldReceiver" component does not exist in the updated apk.

It seems like the "old" code from the existing APK is executed (its application's onCreate() is invoked) trying to access the "new" manifest that exists in the updated APK and can't find the "old" receiver (is this even possible?).

My app also listens to PACAKGE_ADDED & PACKAGE_REMOVED intents.

This crash happens on a relatively large percentage of users.

Any suggestion or clue as to why this bug is happening and how to fix it would be greatly appreciated.


回答1:


There are different ways how to update APK..Im not sure which one you are using.. I faced similar issue .. and it was due to app has multiple instances during updating.. you can make app as single instance or just be sure there are not old instances running. I hope that may help.




回答2:


Since JELLY_BEAN version: Calls to PackageManager.setComponentEnabledSetting will now throw an IllegalArgumentException if the given component class name does not exist in the application's manifest.

It explains why this crash happens on a large percentage of users.




回答3:


Sorry, I cannot confirm whether this would be of any help since I haven't tested it myself.

Maybe you can try disabling your "SomeOldReceiver" (or any other components that might be triggered by the installation of the new package) by making a call to setComponentEnabledSetting() before calling installPackage() ?

Logistically, this might require you to produce an interim version of your app (that added the setComponentEnabledSetting() call before installPackage() and should still have "SomeOldReceiver" in its manifest) to update the old version first. You can then update this version to your real updated version with "SomeOldReceiver" removed.



来源:https://stackoverflow.com/questions/35743983/crash-while-self-updating-apk-component-class-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!