software-mansion / react-native-reanimated

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

App crashes randomly - only Android 12 and mostly Samsung devices #3294

Closed ilyagru closed 11 months ago

ilyagru commented 2 years ago

Description

I'm opening an issue here for one which is reported to the React Native team. Could you take a look please? Maybe it is related? I think the react-native-reanimated team might have some fresh ideas on how to resolve it.

Expected behavior

No crash.

Actual behavior & steps to reproduce

To reproduce you need at least:

  1. Android 12
  2. Samsung device
  3. React Native 0.68.2

Crashes as https://github.com/facebook/react-native/issues/33375#issuecomment-1139618328

Please see the whole thread for more logs and info.

Snack or minimal code example

For example, here is a reproduction https://github.com/facebook/react-native/issues/33375#issuecomment-1059844263 https://github.com/jefersonvinicius/react-native-crashing-example

Package versions

This information is also available in the thread.

name version
react-native 0.68.2
react-native-reanimated ^2.8.0
NodeJS
Xcode
Java
Gradle
expo

Affected platforms

jarredt commented 2 years ago

We are having this issue as well, except we're on React Native 0.64.3. Only seeing it on Samsung devices on Android 12.

jarredt commented 2 years ago

Wondering if https://github.com/software-mansion/react-native-reanimated/issues/3080 is related.

ilyagru commented 2 years ago

Yes @jarredt it seems occuring only on Samsungs with Android 12. #3080 might be related. It looks like many people who updating their devices to Android 12 and start experience the crash, even in different React Native apps. Any ideas for a workaround?

jarredt commented 2 years ago

Nope, spent several days on it and it seemed to be tied to our introduction of reanimated to our app, so we ultimately removed reanimated and went in a different direction.

webdevmario commented 2 years ago

expo: 45.0.0 react-native: 0.68.2 react-native-reanimated: 2.8.0

I too noticed this issue cropping up amongst Android 12/Samsung devices once we upgraded to Expo SDK 45.

Our app makes use of React Navigation 6 and react-native-reanimated is a dependency so I cannot remove it.

I created a minimal Expo test app to evaluate and it is if in fact the addition of this package that causes it to crash on Android 12/Samsung devices. If I remove it, the crashing stops.

3080 does seem to be related.

https://github.com/facebook/react-native/issues/33375 appears to be the root issue/cause. Some comments suggest RN 0.69.0 will address but it would be good to have some confirmation from RN devs + react-native-reanimated devs on Samsung devices.

Below is the code I used for my test. Take out reanimated and it should stop crashing on these devices.

{
  "name": "expo-demo",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/stack": "^6.2.1",
    "expo": "~45.0.0",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "expo-updates": "~0.13.2",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-reanimated": "~2.8.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}
// App.js

import * as SplashScreen from 'expo-splash-screen';
import React, { useEffect, useState } from 'react';
import RootNavigator from './src/navigation/RootNavigator';

export default function App() {
  const [appIsReady, setAppIsReady] = useState(false);

  useEffect(() => {
    async function initApp () {
      try {
        await SplashScreen.preventAutoHideAsync();
      } catch (e) {
        console.log(e);
      } finally {
        setAppIsReady(true);
      }
    }

    initApp();
  }, []);

  if (!appIsReady) {
    return null;
  }

  return (
    <RootNavigator />
  );
}

// RootNavigator.js

import * as SplashScreen from 'expo-splash-screen';
import React, { useEffect, useState } from 'react';
import RootNavigator from './src/navigation/RootNavigator';

export default function App() {
  const [appIsReady, setAppIsReady] = useState(false);

  useEffect(() => {
    async function initApp () {
      try {
        await SplashScreen.preventAutoHideAsync();
      } catch (e) {
        console.log(e);
      } finally {
        setAppIsReady(true);
      }
    }

    initApp();
  }, []);

  if (!appIsReady) {
    return null;
  }

  return (
    <RootNavigator />
  );
}
ilyagru commented 2 years ago

Hi! Any update on this one? RN 0.69.1 hasn't resolved this issue. And since there is a repro, could anyone from maintainers please take a look?

webdevmario commented 2 years ago

@ilyagru Disappointing to read that 0.69.1 does not address. https://github.com/facebook/react-native/issues/33375 has a lot of activity as of late. I noticed this issue says "1 of 3 tasks" complete. Do all 3 need to complete before maintainers start taking a look?

ilyagru commented 2 years ago

@webdevmario "1 of 3 tasks" means it is not related to tasks but to the affected platforms, it occurs only on Android, hence 1 checkbox is checked.

webdevmario commented 2 years ago

@ilyagru Ah, I see. Thank you for clarifying. Definitely just Android. 😫

RhyG commented 2 years ago

Hi, just wondering if anyone knows of any movement on this issue? I can see in the thread in the react-native repo there has been a bunch of comments and a repro, but no updates or fixes. This is currently affecting quite a lot of our users, is there anything that could be done in the meantime to prevent this error from happening? Keen to help where possible, but not at all a native developer sadly.

MuhammadRafeh commented 2 years ago

Any updates?

robertwt7 commented 2 years ago

could this be related to #3234? we are experiencing the same issue, it seems like it happens when using predefined animations, in my case is FadeInUp

joviksdev commented 2 years ago

Having similar issues too, application crashes on android 12, Samsung device, has there been a fix on this?

bangdy commented 2 years ago

I also have crash on my release at first time only for Samsung android 12 phone. I need to maintain react-native-reanimated for react-navigation/drawer. So, not fundamental solution,

  1. I used react-native-restart for resetting app first time only.
  2. I used react-native-device-info check Samsung and 12 version

It could be temporary solution. (In my case, after mounting of navigation's drawer, reset needs to be executed. After a few times of test, I chose 2s)

// MainComponent.js 
...
useEffect(() => {
    const checkFirst = async () => {
      const brand = await getBrand();
      const version = await getSystemVersion();
      getItemFromAsync('notFirst').then(notFirst => {
        if (!notFirst && brand === 'samsung' && version === '12') {
          setItemToAsync('notFirst', true);
          setTimeout(() => {
            RNRestart.Restart();
          }, 2000);
        }
      });
    };

    checkFirst();
  }, []);
...
vincemavill commented 2 years ago

I solve the issue by changing targetSdkVersion = 31 to argetSdkVersion = 30

vjsingh95 commented 1 year ago

maintain react-native-reanimated for react-navigation/drawer. So, not fundamental solution,

How you uploaded the app with targetSdkVersion 30 ? Google play console is asking for target 31 or higher.

codal-mpawar commented 1 year ago

right @vjsingh95 if we need to upload the app on the google play console then it must targetSdkVersion = 31.

jonathanroze commented 1 year ago

Did you find a way to fix this issue ? Thanks

grant-solomons commented 1 year ago

I am also experiencing this issue just on samsung devices

vjsingh95 commented 1 year ago

Please add below line to build gradle file.

implementation 'androidx.work:work-runtime:2.7.1'

jonathanroze commented 1 year ago

Please add below line to build gradle file.

implementation 'androidx.work:work-runtime:2.7.1'

Thanks, I already try this way, an this error is still throw on Android 12!

lakshminarayana254 commented 1 year ago

Any solution for this? Notifications working when app in foreground but in background not working in targetsdkversion 31.

adityabrovitech commented 1 year ago

Any solution for this? Notifications working when app in foreground but in background not working in targetsdkversion 31.

you should add POST_NOTIFICATION permission for targetsdkversion-31 android 13

Arise-cn commented 1 year ago

Did you find a way to fix this issue ? Thanks

Latropos commented 11 months ago

Closing since we have limited our support for Reanimated v2 since release of the Reanimated 3, please upgrade