Failed to retrieve removeGhost method
R

1

7

I'm putting in place the Android Navigation Component in my app.
Some transitions work fine, but for this one I have an error. The transition view, from fragment A, stay on the new fragment (B) and hide some elements. Moreover, when I scroll in the fragment, the view don't scroll with it. This is the error I get:

W/t.qoqa.ui.debu: Accessing hidden method Landroid/view/GhostView;->removeGhost(Landroid/view/View;)V (greylist-max-p, reflection, denied)
I/GhostViewApi21: Failed to retrieve removeGhost method
    java.lang.NoSuchMethodException: android.view.GhostView.removeGhost [class android.view.View]

I start from a RecyclerView in fragment A, where on click I set a unique the transition name.
Then, I pass this name as an argument using SafeArgs along with the view in FragmentNavigatorExtras.

In fragment B, I delay the transition in onCreate: postponeEnterTransition() and set the transition type :

transition = TransitionSet().apply {
    addTransition(ChangeTransform())
    addTransition(ChangeBounds())
    startDelay = 150
}
sharedElementEnterTransition = transition
sharedElementReturnTransition = transition

I set the name in onViewCreated: ViewCompat.setTransitionName(product_image, args.imageTransitionName)

And finally, a Glide Listener start the transition when the image is ready to be shown:

listener = object: RequestListener<Drawable> {
    override fun onLoadFailed(
        e: GlideException?,
        model: Any?,
        target: Target<Drawable>?,
        isFirstResource: Boolean
    ): Boolean {
        startPostponedEnterTransition()
        return false
    }

    override fun onResourceReady(
        resource: Drawable?,
        model: Any?,
        target: Target<Drawable>?,
        dataSource: DataSource?,
        isFirstResource: Boolean
    ): Boolean {
        startPostponedEnterTransition()
        return false
    }
}

And the return transition does not work either.
I'm using only androidx.transition.* elements

Thanks in advance for the help

Rennie answered 11/11, 2019 at 13:59 Comment(0)
M
4

I work in Google on Transitions library. This issue means you have set Android 10(Q) as a targetSdkVersion and using an outdated version of transition library. Older version was using reflection to reach the private methods from Android Framework which is now restricted starting from Q(when you specify it as targetSdk, not compileAdk). Newer version is not using reflection anymore. To fix this you need to update the transition library version to at least 1.2.0 https://developer.android.com/jetpack/androidx/releases/transition#1.2.0

Moten answered 21/11, 2019 at 11:20 Comment(2)
@Andrey In version1.2.0 I'm also getting the same error. It tries to use reflection to find removeGhost method and it failsHolophytic
@Holophytic I am pretty sure it shouldn't happen as there is no reflection left in 1.2.0. are you sure the version was in fact updated? can you please file a bug here issuetracker.google.com/issues/new?component=460400 if it will continue crashing for you. thanksMoten

© 2022 - 2024 — McMap. All rights reserved.