简体   繁体   English

getResources返回null

[英]getResources returns null

We register a broadcast receiver to receive package installment or uninstallment event. 我们注册广播接收器以接收包安装或卸载事件。

But some users report crash reports like this: 但有些用户报告崩溃报告如下:

java.lang.RuntimeException: Unable to create application com.kc.security.MoSecurityApplication: java.lang.RuntimeException: getResources is null: dir - /data/app/com.cm.mg-1.apk, srcVal-1, srcVal-2
at android.app.LoadedApk.makeApplication(LoadedApk.java:495)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2249)
at android.app.ActivityThread.access$1600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: getResources is null: dir - /data/app/com.cm.mg-1.apk, srcVal-1, srcVal-2
at com.kc.security.b.ab.b(UpdateManager.java:69)
at com.kc.security.b.ab.a(UpdateManager.java:112)
at com.kc.security.MoSecurityApplication.onCreate(MoSecurityApplication.java:66)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
at android.app.LoadedApk.makeApplication(LoadedApk.java:492)
... 11 more

It is not easy to reappear this crash. 重现这次崩溃并不容易。 We think a lot about this problem. 我们对这个问题有很多想法。 We receive a 我们收到了
uninstall event ,then the Application context Class called it's onCreate method, we do some initial works there , when we call getResouce(), it returns null . 卸载事件,然后Application上下文类调用它的onCreate方法,我们在那里做一些初始工作,当我们调用getResouce()时,它返回null。 When look deep inside the framework codes, we find that getReource locate resources file by sourceDir String in ApplicationInfo, and the String is "/data/app/com.cm.mg-1.apk" > it's the original apk , and it is not exists anymore. 当深入了解框架代码时,我们发现getReource在ApplicationInfo中通过sourceDir String找到资源文件,而String是“/data/app/com.cm.mg-1.apk”>它是原始的apk,它是不再存在了。

It maybe happens when user update our application. 当用户更新我们的应用程序时可能会发生 In some way "/data/app/com.cm.mg-1.apk" is allready deleted and replace by "/data/app/com.cm.mg-2.apk" any way, but the "sourceDir" String in ApplicationInfo is not update. 在某种程度上“/data/app/com.cm.mg-1.apk”已经全部删除并以“/data/app/com.cm.mg-2.apk”替换,但是“sourceDir”字符串在ApplicationInfo中没有更新。

I want to know what android does when doing a updating. 我想知道android在进行更新时会做什么。

Encountered a similar problem, check this out. 遇到类似的问题,看看这个。

RuntimeException: Unable to instantiate application RuntimeException:无法实例化应用程序

I think this should answer this question, maybe because the Resources has been destroyed during this uninstall event. 我认为这应该回答这个问题,可能是因为在此卸载事件期间资源已被销毁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM