software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.13k stars 982 forks source link

Crash on scrolling inside <Animated.Scrollview ../> : java.lang.NoSuchMethodError: No virtual method reversed() #2961

Closed ram95krishh closed 4 months ago

ram95krishh commented 4 months ago

Description

App crashes whenever we scroll inside a Animed.ScrollView that uses React Native Gesture Handler. Not sure if the issue is directly related to this library, I am posting it in both react-native github issues https://github.com/facebook/react-native/issues/45178 and here. Please upvote (šŸ‘) or comment if anybody else is also facing this since the app:checkDevelopmentRechargeDebugAarMetadata step started mandating projects to start supporting compileSdkVersion 35 (for Android VanillaIceCream)

<Animated.ScrollView.. /> internally uses react-native-gesture-handler. We recently upgraded the compileSDKVersion support to 35 as it is mandatory to support AndroidVanillaIceCream going forward..

Whenever we scroll in our Animated ScrollViews it crashes the android app. Found this in the crash logs:

java.lang.NoSuchMethodError: No virtual method reversed()Ljava/util/List; in class Ljava/util/ArrayList; or its super classes (declaration of 'java.util.ArrayList' appears in /apex/com.android.art/javalib/core-oj.jar)
at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.makeActive(GestureHandlerOrchestrator.kt:193)
at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.tryActivate(GestureHandlerOrchestrator.kt:102)
at com.swmansion.gesturehandler.core.GestureHandlerOrchestrator.onHandlerStateChange(GestureHandlerOrchestrator.kt:154)
at com.swmansion.gesturehandler.core.GestureHandler.moveToState(GestureHandler.kt:568)
at com.swmansion.gesturehandler.core.GestureHandler.activate(GestureHandler.kt:671)
at com.swmansion.gesturehandler.core.GestureHandler.activate(GestureHandler.kt:667)
at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.tryCancelAllHandlers(RNGestureHandlerRootHelper.kt:112)
at com.swmansion.gesturehandler.react.RNGestureHandlerRootHelper.requestDisallowInterceptTouchEvent(RNGestureHandlerRootHelper.kt:93)
at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.requestDisallowInterceptTouchEvent(RNGestureHandlerRootView.kt:47)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.view.ViewGroup.requestDisallowInterceptTouchEvent(ViewGroup.java:3244)
at android.widget.ScrollView.onInterceptTouchEvent(ScrollView.java:659)
at com.facebook.react.views.scroll.ReactScrollView.onInterceptTouchEvent(ReactScrollView.java:409)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2653)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at com.swmansion.gesturehandler.react.RNGestureHandlerRootView.dispatchTouchEvent(RNGestureHandlerRootView.kt:38)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3121)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2802)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:500)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1905)
at android.app.Activity.dispatchTouchEvent(Activity.java:4263)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:458)
at android.view.View.dispatchPointerEvent(View.java:15262)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6654)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6454)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5910)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5967)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5933)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6098)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5941)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6155)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5914)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5967)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5933)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5941)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5914)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8996)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8947)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8916)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9119)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:267)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:247)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:9076)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:9210)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
at android.view.Choreographer.doCallbacks(Choreographer.java:899)
at android.view.Choreographer.doFrame(Choreographer.java:824)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Thanks in advance, Rama!

Steps to reproduce

App crashes whenever scrolled inside such scroll views.

const MyComponent = () => {
  const scrollY = useAnimatedValue()
  return (
    <Animated.ScrollView
      onScroll={Animated.event(
        [{ nativeEvent: { contentOffset: { y: scrollY } } }],
        { useNativeDriver: true }
      )}
    >
      {content}
   </Animated.ScrollView>
  )
}

Snack or a link to a repository

https://snack.expo.dev/1XT8GU8hlsNThnmMjYB2Y

Gesture Handler version

2.14.0

React Native version

0.73.8

Platforms

Android

JavaScript runtime

None

Workflow

React Native (without Expo)

Architecture

None

Build type

Debug mode

Device

Android emulator

Device model

Pixel 6

Acknowledgements

Yes

j-piasecki commented 4 months ago

I tried your repro but it doesn't depend on Gesture Handler in any way. I updated it to use it where it made sense to me

here's the modified code ```jsx import React from 'react'; import { Animated, Text, StyleSheet, useAnimatedValue } from 'react-native'; import { Gesture, GestureDetector } from 'react-native-gesture-handler'; // You can import supported modules from npm import { Card } from 'react-native-paper'; function Item() { const tap = Gesture.Tap().onStart(() => { console.log('tap'); }); return ( Example Code ); } export default function App() { const scrollY = useAnimatedValue(0, { useNativeDriver: true }); const nativeGesture = Gesture.Native(); return ( On scrolling in this Animated.ScrollView, the android app crashes when built using compileSDKVersion 35. {new Array(20).fill(null).map((_, index) => ( ))} ); } const styles = StyleSheet.create({ container: { flex: 1, flexGrow: 1, backgroundColor: '#ecf0f1', padding: 8, }, contentContainer: { justifyContent: 'center', paddingHorizontal: 16, paddingBottom: 40, gap: 8, }, paragraph: { margin: 8, fontSize: 18, fontWeight: 'bold', textAlign: 'center', }, }); ```

But it didn't crash for me then:

https://github.com/software-mansion/react-native-gesture-handler/assets/21055725/f5165d42-49f8-4300-8ffc-6b9eb4ae8a8a

internally uses react-native-gesture-handler.

No component from React Native itself relies on Gesture Handler internally.

Could you prepare a repository with an app that would allow to reproduce it out of the box?

ram95krishh commented 4 months ago

Hey @j-piasecki, thanks for checking this. I tried a hello world project with just the Animated ScrollView. Like you said the Gesture Handler is not a dependency and the app didn't crash at all. I am trying to find if some gesture listener in my project is acting up. I'll close the issue I raised as it seems unrelated to what I've reported here.. I will reopen an issue if I'm able to pinpoint the cause and if it happens to be a bug. Apologies for the confusion!

skyplor commented 4 months ago

Hi @ram95krishh did you manage to find out the reason for this? I also had this issue after upgrading to support API 35 while testing it on my android 31 device

skyplor commented 4 months ago

Just for future references or anyone who also encountered this issue. The issue was somehow due to the usage of kotlin version 1.8.0

Solution

We would need to update the kotlin's version to 1.9.0

j-piasecki commented 4 months ago

Hmm, that's interesting - RNGH already adds a dependency on kotlin-stdlib. Would it be possible for you to check if it detects the Kotlin version correctly?

skyplor commented 4 months ago

Hi @j-piasecki I've just realised that it works even without the dependencies block in my app's build.gradle. What actually worked was me changing the kotlinVersion declaration in my project's build.gradle from 1.8.0 to 1.9.0.

Let me update my comment above to reflect this finding

stelioskat commented 1 month ago

Just for future references or anyone who also encountered this issue. The issue was somehow due to the usage of kotlin version 1.8.0

Solution

We would need to update the kotlin's version to 1.9.0

I can confirm this solves the crashing issue. Thanks!

Inayat567 commented 5 days ago

Hi @ram95krishh did you manage to find out the reason for this? I also had this issue after upgrading to support API 35 while testing it on my android 31 device

Thanks a lot @skyplor for this message, you saved me! I was struggling since last 7 hour