自更新APK时崩溃(组件类不存在) [英] Crash while self updating APK (component class does not exist)

查看:44
本文介绍了自更新APK时崩溃(组件类不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个系统应用程序,该应用程序通过下载 apk 并使用 PackageManager 的 installPackage() 方法安装它来更新自身.

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

我收到以下异常:

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 ...

更新后的 apk 中不存在SomeOldReceiver"组件.

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

似乎执行了现有 APK 中的旧"代码(调用了其应用程序的 onCreate()),试图访问更新后的 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?).

我的应用程序还收听 PACAKGE_ADDED &PACKAGE_REMOVED 意图.

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.

推荐答案

抱歉,我无法确认这是否有任何帮助,因为我自己没有测试过.

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

也许您可以尝试通过调用 setComponentEnabledSetting() 在调用 installPackage() 之前?

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() ?

从逻辑上讲,这可能需要您生成应用程序的临时版本(在 installPackage() 之前添加了 setComponentEnabledSetting() 调用,并且仍应具有SomeOldReceiver"在其清单中)首先更新旧版本.然后,您可以将此版本更新为真正的更新版本,并删除SomeOldReceiver".

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.

这篇关于自更新APK时崩溃(组件类不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆