software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.12k stars 1.32k forks source link

java.lang.IndexOutOfBoundsException: index=2 count=0 on Android #6519

Closed jacobarvidsson closed 2 months ago

jacobarvidsson commented 2 months ago

Description

We are getting this error when react native is initialising (app start). We started seeing this after upgrading from react-native 0.73.8 to 0.74.5. We have tried several react-native-reanimated versions, 3.8.0, 3.14.0 and 3.15.1.

The issue is difficult to reproduce manually but happens on every other PR running our automated appium tests on Saucelabs. The issue does not seem to happen to every device, but mostly pixel devices running android 12.

java.lang.IndexOutOfBoundsException: index=2 count=0
    at android.view.ViewGroup.addInArray(ViewGroup.java:5404)
    at android.view.ViewGroup.addViewInner(ViewGroup.java:5297)
    at android.view.ViewGroup.addView(ViewGroup.java:5104)
    at android.view.ViewGroup.addView(ViewGroup.java:5044)
    at com.facebook.react.uimanager.ViewGroupManager.addView(ViewGroupManager.java:38)
    at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:533)
    at com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren(ReanimatedNativeHierarchyManager.java:300)

The issue has previously been reported here: https://github.com/software-mansion/react-native-reanimated/issues/3856 however the issue is not the same as the author describes, though it is the same issue as several of the comments mentions.

Issue seems to happen on multiple react native and reanimated versions. Some comments seems to hint on the fact that LayoutAnimations could be the cause, however we are able to reproduce this even with LayoutAnimations disabled.

Steps to reproduce

  1. Start the app, the issue appears as soon as react-native is loading.

Snack or a link to a repository

No specific code causes this issue, its during the start of the app.

Reanimated version

3.15.1

React Native version

0.74.5

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Debug app & production bundle

Device

Real device

Device model

Google Pixel 4

Acknowledgements

Yes

github-actions[bot] commented 2 months ago

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?

hamdij0maa commented 2 months ago

+1

rosen777 commented 2 months ago

+1

RomanZahradnikSalams commented 2 months ago

+1

RomanZahradnikSalams commented 2 months ago

I have created a hacky way to get rid of the error at least until package maintainers will come up with the solution

react-native-reanimated+3.15.3.patch

index ab0e79b..ee2e201 100644
--- a/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java
+++ b/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java
@@ -334,7 +334,11 @@ public class ReanimatedNativeHierarchyManager extends NativeViewHierarchyManager
       @Nullable ViewAtIndex[] viewsToAdd,
       @Nullable int[] tagsToDelete) {
     if (isLayoutAnimationDisabled()) {
-      super.manageChildren(tag, indicesToRemove, viewsToAdd, tagsToDelete);
+      try {
+        super.manageChildren(tag, indicesToRemove, viewsToAdd, tagsToDelete);
+      } catch (Exception e) {
+
+      }
       return;
     }
     ViewGroup viewGroup;
piaskowyk commented 2 months ago

Hey, it seems like this is not a Reanimated-related issue. This problem appears to stem from React Native. You can find more information here: https://github.com/facebook/react-native/issues/16411