Skip to content

Instantly share code, notes, and snippets.

@adamblvck
Created March 2, 2023 11:23
Show Gist options
  • Save adamblvck/317b36ab64dd55b2bd29cc9c7d4ad1b8 to your computer and use it in GitHub Desktop.
Save adamblvck/317b36ab64dd55b2bd29cc9c7d4ad1b8 to your computer and use it in GitHub Desktop.
Expo Plugin for enabling `android:largeHeap` flag in AndroidManifest, allowing one to process more data in memory (useful when reading large JSON files).
const { withAndroidManifest } = require("@expo/config-plugins");
module.exports = function androiManifestPlugin(config) {
return withAndroidManifest(config, async (config) => {
let androidManifest = config.modResults.manifest;
androidManifest.application[0].$["android:largeHeap"] = "true";
return config;
});
};
/**
Usage:
1. Add this file to your project (eg: ./plugins/withAndroidMainActivityAttributes.js)
2. Specify the plugin file in App Config:
"plugins": [
[
... some plugin ...
],
[
"./plugins/withAndroidMainActivityAttributes" <--
],
[
... another plugin ...
]
],
3. Build your Expo App using EAS Build
4. Proceed developing as usual.
Notes:
- You can use ClassyShark to check the AndroidManifest of the EAS-built `apk` file, and search for the largeHeap flag.
- Many "online-first snobs" on the internet discourage the largeHeap flag, however being essential for offline-first use cases. When having largeHeap enabled, always profile your RAM usage, and tackle memory leaks as soon as possible.
*/
@adamblvck
Copy link
Author

I recommend changing the filename of this file to "enableLargeHeap.js" - a more practical and useful indication of the content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment