Skip to content

Fixing React Native Android crashes: FlatList recycling, memory and R8

Production crash fixes from the Melodius Android app: removeClippedSubviews under the New Architecture, a list nested in a ScrollView, unhandled browser intents, and turning on R8 for release builds.

3 min read

The Melodius Android app is built with Expo and React Native. Crash reports from real phones pointed at a few causes that are easy to hit in any React Native app. Here they are with the fixes.

removeClippedSubviews and the New Architecture

FlatList turns removeClippedSubviews on by default on Android. With the New Architecture, re-inserting a clipped view can fail with "addViewAt: failed to insert view". Worse, React Native's diagnostic dump of that failure formats every mount item and can run the app out of memory, so one crash became two. The horizontal shelves and the genre list now turn the option off; the reorderable lists already did.

A list that was not virtualized

The playlist screen put its list inside a ScrollView with list scrolling disabled, so the list rendered every row at once. A long imported playlist meant thousands of native views: the Java heap near its limit, garbage-collection stalls on the main thread that surfaced as ANRs, and out-of-memory crashes. It is now one virtualized list with the playlist header as its header component.

Phones without a usable browser

Sign-in and connecting Discord or Spotify open a browser. On phones without one able to handle the intent, the promise rejected unhandled and crashed. Now the app catches it and tells the listener what is missing.

Shrinking the release with R8

Google Play reported the app's code as 1% obfuscated, far under its threshold. A small Expo config plugin enables minifyEnabled for release builds, including EAS builds, since theandroid/ folder is generated. Libraries ship their own keep rules, so no manual rules were needed.

  • The release APK dropped from 109 MB to 98 MB.
  • Resource shrinking stays off, because React Native finds bundled images by name at runtime and shrinking would strip them.
  • Play deobfuscates crash reports from the mapping inside the bundle; Sentry needs the mapping uploaded separately, or its stack traces become unreadable.

More on how the Android app shares code with the web and desktop in one music app on four platforms.

Illustrated avatar of Kumar Manas

Written by Kumar Manas

Full-stack developer in India. I build Melodius and Krypton.

Related projectMelodius: music streaming platform