Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not retrieve mAdded field from class androidx.fragment.app.FragmentManagerImpl #931

Closed
benoitdion opened this issue Mar 26, 2020 · 4 comments
Assignees
Labels
Android bug Something isn't working question Further information is requested

Comments

@benoitdion
Copy link

馃悰 Bug Report

It looks like we're looking for a mAdded field

on FragmentManagerImpl but that field doesn't exist:
https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManagerImpl.java
mAdded exists on the fragment themselves but not the manager.

Would https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java#934 be useful for what we're trying to do here?

Stacktrace:

2020-03-26 13:01:23.808 8969-8969/com.mypackage E/com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.ReflectionUtil: Could not retrieve mAdded field from class androidx.fragment.app.FragmentManagerImpl
    java.lang.NoSuchFieldException: No field mAdded in class Landroidx/fragment/app/FragmentManagerImpl; (declaration of 'androidx.fragment.app.FragmentManagerImpl' appears in /data/app/com.mypackage-5E855k89Sn36xw35D2A==/base.apk)
        at java.lang.Class.getDeclaredField(Native Method)
        at com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.ReflectionUtil.tryGetDeclaredField(ReflectionUtil.java:29)
        at com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.FragmentCompat$FragmentManagerAccessorViaReflection.getAddedFragments(FragmentCompat.java:88)
        at com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.FragmentCompatUtil.findFragmentForViewInFragmentManager(FragmentCompatUtil.java:82)
        at com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.FragmentCompatUtil.findFragmentForViewInActivity(FragmentCompatUtil.java:73)
        at com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.FragmentCompatUtil.findFragmentForViewInActivity(FragmentCompatUtil.java:48)
        at com.facebook.flipper.plugins.inspector.descriptors.utils.stethocopies.FragmentCompatUtil.findFragmentForView(FragmentCompatUtil.java:39)
        at com.facebook.flipper.plugins.inspector.descriptors.ViewGroupDescriptor.getAttachedFragmentForView(ViewGroupDescriptor.java:321)
        at com.facebook.flipper.plugins.inspector.descriptors.ViewGroupDescriptor.getChildAt(ViewGroupDescriptor.java:132)
        at com.facebook.flipper.plugins.inspector.descriptors.ViewGroupDescriptor.getChildAt(ViewGroupDescriptor.java:32)
        at com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin$14.runOrThrow(InspectorFlipperPlugin.java:593)
        at com.facebook.flipper.core.ErrorReportingRunnable.run(ErrorReportingRunnable.java:24)
        at com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin.getNode(InspectorFlipperPlugin.java:597)
        at com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin.access$300(InspectorFlipperPlugin.java:31)
        at com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin$5.onReceiveOnMainThread(InspectorFlipperPlugin.java:203)
        at com.facebook.flipper.plugins.common.MainThreadFlipperReceiver$1.run(MainThreadFlipperReceiver.java:29)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

To Reproduce

Layout inspector with android x fragments

Environment

Flipper desktop mac, flipper for android 0.34

@passy
Copy link
Member

passy commented Mar 27, 2020

Thanks for reporting this! Do you by any chance have a code snippet that could help us to reproduce this a bit faster?

@passy passy self-assigned this Mar 27, 2020
@passy passy added Android bug Something isn't working labels Mar 27, 2020
@passy
Copy link
Member

passy commented Mar 30, 2020

I tried to replicate this but I'm not quite sure what's needed to trigger the codepath. I've changed the sample app a bit, but this doesn't seem to be quite enough: https://github.com/facebook/flipper/tree/androidx-fragment

Screenshot 2020-03-30 17 33 45

Things are still working as expected. @benoitdion Could you provide some more steps?

@passy passy added the question Further information is requested label Mar 30, 2020
@benoitdion
Copy link
Author

Thanks for looking into this @passy!

A couple of clarifications on the initial bug report

  • The stacktrace posted does not cause a crash. Our app quickly runs out of memory when using the layout inspector in heavy screens but it's unrelated to this.
  • The easiest way to tweak the example app to repro is to change FragmentCompat line 40 to ReflectionUtil.tryGetClassForName("androidx.fragment.app.Fragment") != null

@passy
Copy link
Member

passy commented Apr 1, 2020

Thanks, @benoitdion! I got a repro now. It looks like the androidx migration we did was a bit haphazard. I'll try to get this fixed in the next few days.

passy added a commit that referenced this issue Apr 1, 2020
Summary:
Fix #931

This is not how I would *like* to fix this, but it should do the job.
When the switch over to AndroidX was made, the overall abstraction
started to leak and we really need to remodel this in its entirety.
There's also the question of whether we want to support both support
fragments and AndroidX fragments or not. Right now it's kinda-sorta
supported but only under some circumstances, which is not great.

Test Plan:
Changed the sample app to include some AndroidX fragments and they
now show up (again) in the view hierarchy:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants