Sorry to revive old topic, but I'm encountering same issues with my app:
System-privileged app having android:persistent=true fails to update properly, crashes.
What I'm seeing is that the system installs the update while the current (system-installed) version is still running. During the update the system does not stop the process (either attempts to stop and fails or doesn't try at all). After the update completes, the app seems to undergo a "restart" - I'm seeing components being initialized such as Application::onCreate() being called. But this is happening on same process as before the update!
Consequently (upon launching some activity of the app), the app crashes with "weird" exceptions such as failing to cast class to itself:
Caused by: java.lang.ClassCastException: com.XX.YY.ZZ.ClassName cannot be cast to com.XX.YY.ZZ.ClassName
While investigating, I'm seeing the ClassLoader used after the update does not refer to the the path of the updated APK, but remains pointing to the path of the original version:
Expected classloader: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app.package-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app.package-1/lib/x86_64, /data/app/com.app.package-1/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]]
Actual classloader: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/priv-app/Appname.apk"],nativeLibraryDirectories=[/system/lib64/Start, /system/priv-app/Appname.apk!/lib/x86_64, /system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]]]
I'm assuming this is a result of not restarting the process during update.
Is it confirmed that there is not way to update such app via the normal update procedure (e.g. posting newer version on Google Play)? Or is there a way to update an app with persistent=true?