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.