问题
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
回答1:
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
来源:https://stackoverflow.com/questions/58802828/failed-to-retrieve-removeghost-method