Crash while self updating APK (component class does not exist)
<p>I am working on a system application which updates itslef by downloading an apk and installing it by using PackageManager's <code>installPackage()</code> method.</p>

<p>I am getting the following exception:</p>

<pre><code>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 ...
</code></pre>

<p>The "SomeOldReceiver" component does not exist in the updated apk.</p>

<p>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?).</p>

<p>My app also listens to PACAKGE_ADDED &amp; PACKAGE_REMOVED intents.</p>

<p>This crash happens on a relatively large percentage of users.</p>

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