Skip to content

Resource$NotFoundException in plug-in project #1385

@y4n9b0

Description

@y4n9b0
  • 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.

Activity

added a commit that references this issue on Jul 3, 2019
pyricau

pyricau commented on Jul 3, 2019

@pyricau
Member

@1step2hell I merged #1435 which I'm hoping fixes this. The fix will be available in alpha 3, let me know if it works!

added this to the 2.0 Next Release milestone on Jul 3, 2019
y4n9b0

y4n9b0 commented on Jul 4, 2019

@y4n9b0
Author

@1step2hell I merged #1435 which I'm hoping fixes this. The fix will be available in alpha 3, let me know if it works!

It doesn't work. Technically both resumedActivity and resumedActivity.application belong to the same apk(unless plug-in lib intercept plugin apk's application and replace it with host apk's application), still can not find resources of host apk.

Here is my solution(replace resumedActivity with current context while creating inflater):

val inflater = LayoutInflater.from(context)

You can replace replace resumedActivity with current context while creating toast too, this step is not necessary, just make the logic more reasonable( resumedActivity only used for condition check):

val toast = Toast(context)

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.

pyricau

pyricau commented on Jul 4, 2019

@pyricau
Member

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.

added a commit that references this issue on Jul 4, 2019
sing0055

sing0055 commented on Dec 17, 2020

@sing0055

I have the same issue:

android.content.res.Resources$NotFoundException: Resource ID #0x7f0b03a0
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
    at android.content.res.Resources.getDimensionPixelSize(Resources.java:745)
    at leakcanary.internal.AndroidHeapDumper$showToast$1.run(AndroidHeapDumper.kt:95)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7678)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pyricau@y4n9b0@sing0055

        Issue actions

          Resource$NotFoundException in plug-in project · Issue #1385 · square/leakcanary