-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
Milestone
Description
- plug-in project(see DroidPlugin or atlas if never used plug-in project before)
- LeakCanary version >= 1.6.2
Meet the conditions above, LeakCanary crashed while a memory leak was detected.
Here is the log(LeakCanary v1.6.3):
--------- beginning of crash
2019-05-23 20:44:24.511 2544-2544/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx, PID: 2544
android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0183
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:211)
at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:94)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2158)
at android.content.res.Resources.getLayout(Resources.java:1156)
at android.view.LayoutInflater.inflate(LayoutInflater.java:425)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.squareup.leakcanary.AndroidHeapDumper$2.run(AndroidHeapDumper.java:117)
at android.os.Handler.handleCallback(Handler.java:793)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6701)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
This happened due to #1116.
In fixed commit patch, LeakCanary listen lifecycle to get a resumed activity, then inflate toast contentView with this resumed activity.
A plug-in project include multiple apks: one is host apk, others are plugin apk. We started App with host apk, the plugin apk was loaded dynamically. When listen lifecycle, we might get a resumed activity belongs to plugin apk, but the toast layout resource exists in the host apk. Find the host apk resource with current plugin apk inflater, App crashed.
This crash was noticed once by @Mrnoknow in #196, still exists in version 2.0.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
Select code repository
Activity
Inflate leak toast from application context
Inflate leak toast from application context (#1435)
pyricau commentedon Jul 3, 2019
@1step2hell I merged #1435 which I'm hoping fixes this. The fix will be available in alpha 3, let me know if it works!
y4n9b0 commentedon Jul 4, 2019
It doesn't work. Technically both
resumedActivity
andresumedActivity.application
belong to the same apk(unless plug-in lib intercept plugin apk'sapplication
and replace it with host apk'sapplication
), still can not find resources of host apk.Here is my solution(replace
resumedActivity
with currentcontext
while creating inflater):You can replace replace
resumedActivity
with currentcontext
while creating toast too, this step is not necessary, just make the logic more reasonable( resumedActivity only used for condition check):Dynamic apk loading tech is not supported by google, which makes this issue is more like a bug of plug-in library. Thanks for the favor.
Use application context for toast inflate
pyricau commentedon Jul 4, 2019
Thanks, updated: #1442
I'm sticking to the resumed activity for the toast itself because we've had bugs related to foreground / background in the past when using the app context.
Use application context for toast inflate (#1442)
sing0055 commentedon Dec 17, 2020
I have the same issue:
val iconSize = resumedActivity.resources.getDimensionPixelSize( R.dimen.leak_canary_toast_icon_size )
'R.dimen.leak_canary_toast_icon_size ' can not found in a plugin activity
2 remaining items