Created
March 2, 2023 11:23
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend changing the filename of this file to "enableLargeHeap.js" - a more practical and useful indication of the content