Search code examples
androidreact-nativeexposentry

React Native Expo Android crashes only in production and is also not catchable in Sentry


Already tried to look into all different problems here on StackOverflow with related titles, like this one. But no success.

Here is the piece of code where the problem happens:

const fetchApi = useCallback(async () => {
  setIsLoading(true);

  if (activePortfolioId) {
    try {
      const response = await getApis().portfoliosApi.getPortfolioOverviewById(
        activePortfolioId
      );
      if (response.data && response.data?.tickers?.length) {
        setItems(handleListItems(response.data.tickers));
      }
    } catch (error) {
      Sentry.Native.captureException(error);
      Sentry.Native.captureMessage('HELLO?');
      Alert.alert(
        'Sorry!',
        'We were unable to retrieve the performance list. Please try again later.'
      );
    } finally {
      setIsLoading(false);
    }
  }
}, [activePortfolioId]);

So what happens is, on iOS I have no problem at all here, either on DEV or PROD, using real device or simulator, everything works fine, never went to the catch statement. On Android, using simulator or real device with Expo, it's all fine too, even using expo start --no-dev --minify to try to reproduce the app as PROD, occurs no errors at all. I have tried everything that came on my mind, like removing pieces of the code to see if the problem stops. Like instead of calling the API, just setting the items, like this:

setItems(handleListItems(response.data.tickers)); because I also thought that the problem might be with my handler function, I also tried to just do setItems([{ OBJECT HERE }]);. The problem has just stopped once I stopped setting the items. So I also tried to check my renderItem function, tried to stop using any styled component, just what React Native provides, nothing works. Then I decided to bring Sentry to my code but even with Sentry, no issues is shown there. I open the screen, it is loading, fetches the API, then it falls in the catch block, because I see the Alert on Android and then the app crashes and go back to the splash screen frozen. The only issue that appeared on Sentry was:

Could not open URL 'https://XXXXXXX': No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://XXXXXXX... flg=0x10000000 }

But strangely I have never clicked on this during the "tests" and this link just appears on the login screen, shouldn't have anything to do with the problem itself, right?

I really don't know what else I could try to do and figure out what is causing this problem, so decided to ask for help and maybe find someone who already went through something similar.

Thanks!

PS: I'm using TS too, so apparently no problems with some possible undefined or whatever.


Solution

  • Found the issue, it was with the Intl. Solution here.