Crash on some devices (e.g. Samsung S21) with targetSdkVersion 35 due to NoSuchMethodError: reversed()
Hello,
We've encountered a fatal crash on some devices (e.g., Samsung Galaxy S21 5G, Android 14) but not on others (e.g., Samsung Galaxy A15, Android 14) after updating our app to targetSdkVersion = 35 to meet the new Google Play requirements. The app crashes with java.lang.NoSuchMethodError: No virtual method reversed()Ljava/util/List; in class Ljava/util/ArrayList; originating from GestureHandlerOrchestrator.kt. After extensive debugging, we found that the issue is resolved by replacing all instances of .reversed() with .asReversed() in GestureHandlerOrchestrator.kt. The issue seems to be related to an incompatibility between the bytecode generated for the reversed() extension function and the specific runtime environment on some devices when targeting API 35. The attached patch fixes the issue and makes the app stable on all our test devices with targetSdkVersion = 35.
Thank you for your amazing work on this library!
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-gesture-handler/android/.classpath b/node_modules/react-native-gesture-handler/android/.classpath
new file mode 100644
index 0000000..bbe97e5
--- /dev/null
+++ b/node_modules/react-native-gesture-handler/android/.classpath
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
+ <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
+ <classpathentry kind="output" path="bin/default"/>
+</classpath>
diff --git a/node_modules/react-native-gesture-handler/android/.project b/node_modules/react-native-gesture-handler/android/.project
new file mode 100644
index 0000000..ccf7bb5
--- /dev/null
+++ b/node_modules/react-native-gesture-handler/android/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>react-native-gesture-handler</name>
+ <comment>Project react-native-gesture-handler created by Buildship.</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
+ </natures>
+ <filteredResources>
+ <filter>
+ <id>1753015438075</id>
+ <name></name>
+ <type>30</type>
+ <matcher>
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
+ <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+ </matcher>
+ </filter>
+ </filteredResources>
+</projectDescription>
diff --git a/node_modules/react-native-gesture-handler/android/.settings/org.eclipse.buildship.core.prefs b/node_modules/react-native-gesture-handler/android/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..1675490
--- /dev/null
+++ b/node_modules/react-native-gesture-handler/android/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=../../../android
+eclipse.preferences.version=1
diff --git a/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt b/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
index ebcbb0d..60cc091 100644
--- a/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
+++ b/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
@@ -187,18 +187,18 @@ class GestureHandlerOrchestrator(
activationIndex = [email protected]++
}
- for (otherHandler in gestureHandlers.asReversed()) {
- if (shouldHandlerBeCancelledBy(otherHandler, handler)) {
+for (otherHandler in gestureHandlers.asReversed()) {
+ if (shouldHandlerBeCancelledBy(otherHandler, handler)) {
otherHandler.cancel()
- }
}
+}
- // Clear all awaiting handlers waiting for the current handler to fail
- for (otherHandler in awaitingHandlers.reversed()) {
- if (shouldHandlerBeCancelledBy(otherHandler, handler)) {
+// Clear all awaiting handlers waiting for the current handler to fail
+for (otherHandler in awaitingHandlers.asReversed()) {
+ if (shouldHandlerBeCancelledBy(otherHandler, handler)) {
otherHandler.isAwaiting = false
- }
}
+}
cleanupAwaitingHandlers()
// At this point the waiting handler is allowed to activate, so we need to send BEGAN -> ACTIVE event
@@ -239,18 +239,18 @@ class GestureHandlerOrchestrator(
}
}
- private fun cancelAll() {
- for (handler in awaitingHandlers.reversed()) {
- handler.cancel()
+private fun cancelAll() {
+ for (handler in awaitingHandlers.asReversed()) {
+ handler.cancel()
}
// Copy handlers to "prepared handlers" array, because the list of active handlers can change
// as a result of state updates
preparedHandlers.clear()
- preparedHandlers.addAll(gestureHandlers)
+preparedHandlers.addAll(gestureHandlers)
- for (handler in gestureHandlers.reversed()) {
- handler.cancel()
- }
+for (handler in gestureHandlers.asReversed()) {
+ handler.cancel()
+}
}
private fun deliverEventToGestureHandler(handler: GestureHandler<*>, sourceEvent: MotionEvent) {
This issue body was partially generated by patch-package.
Hey! 👋
It looks like you've omitted a few important sections from the issue template.
Please complete Description, Steps to reproduce, A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug., Gesture Handler version, React Native version and Platforms sections.
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
Getting the same issue after updating our app to targetSdkVersion = 35.
Hi! Fix for this was released on Monday in 2.27.2.
Hi! Fix for this was released on Monday in 2.27.2.
Thanks so much! Just curious—since we're currently upgrading to React Native 0.77, will the new react-native-gesture-handler version 2.27.2 work with it, or do we actually need to upgrade to 0.78 as recommended?
Hi @DonghaoLyu! I'm afraid that it won't build on 0.77 😞 You can try, but I can't guarantee that.
Thanks, this solved my problem.
Hi! Fix for this was released on Monday in 2.27.2.你好!这个问题的修复在周一发布了 2.27.2 版本。
Thanks so much! Just curious—since we're currently upgrading to React Native 0.77, will the new
react-native-gesture-handlerversion 2.27.2 work with it, or do we actually need to upgrade to 0.78 as recommended?非常感谢!只是好奇——既然我们目前正在升级到 React Native 0.77,新的react-native-gesture-handler2.27.2 版本能兼容它吗?还是我们真的需要按照建议升级到 0.78?
I would like to ask if you can successfully build it on 0.77?