Android Development doesn’t work great in less than 8GB memory.
- Reduce the maximum heap size available to Android Studio
- Update Gradle and the Android plugin for Gradle
- Enable Power Save Mode
- Disable unnecessary link checks
- Debug on a physical device
- Include only necessary Google Play Services as dependencies
- Reduce the maximum heap size available for DEX file
- Do not enable parallel compilation
- Turn on Offline Mode for Gradle
Reference:
1. StackOverflow: Android studio takes too much memory
2. Configure the IDE for low-memory machines