How to stop android studio from crashing the whole computer?
I installed android studio and it crashed several times. I installed an older version (Arctic fox) and it did the same. It never managed to install gradle. I installed gradle via the command line (using apt). Then android studio complained that the gradle libraries were newer. And crashed. I installed the latest version of android studio via the command line. It goes a bit further sometimes, I was able to create a new project and to give it a name. But I can’t do anything else.
Hardware acceleration is unavailable on my machine.
Each time, I have to hard reboot the computer.
It doesn’t always crash at the same stage. It starts doing something, for example indexing files, and then it crashes. Currently, it’s going to crash while building gradle. I test it by moving the mouse pointer. When the mouse pointer stops moving completely, I know nothing else is going to happen and I press the button.
There you go, while I’m typing this, it has crashed the other computer. Power off.
Is there a way to contain it, to slow it down, to stop it from using all the RAM? I wouldn’t mind giving it more time to finish whatever it thinks it’s got to do, even leaving it to run overnight, but I would like the rest of the computer to remain functional.
Is there any lighter alternative? Should I reinstall lubuntu and everything leaving out the android preview? (Anyway I can’t use it currently because I never found the "Split" button which google mentions in it’s android tutorial). I don’t really mind doing a new lubuntu install as this is a new machine. I have nothing personal on it except a nice desktop wallpaper.
All suggestions welcome.
Solution 1: Lower Android Studio’s JVM’s max memory
You can tell Android Studio to use less memory if your computer doesn’t have enough.
- Open the file
- Replace (add if missing)
-Xmx4096m) with lower values such as
-Xmsto the same value
- Restart Android Studio
Solution 2: Lower Gradle’s JVM’s max memory
You can have Gradle use less memory when building projects.
- Open or create the file
- Add or merge the line
- Add or merge the line
- Locally delete those lines in
gradle.propertiesin any Android project you are working in before opening them, to avoid them overriding the above settings
- Kill all processes related to Gradle, or reboot
Solution 3: Limit it with a cgroup
cgroups are a way to impose many resource consumption limits on a specific set of processes.
/sys/fs/cgroup is complicated, so let’s just use
- Enter a subshell in a new memory-limited cgroup with
systemd-run --user --scope -p MemoryMax=2G bash
- Start Android Studio with
~/.local/share/JetBrains/Toolbox/apps/android-studio/bin/studio.shor wherever you installed it
Solution 4: Reduce Android development resource consumption
There are other tips you can use while developing Android projects:
- Disable "File > Power Save Mode". You said it crashes when indexing files, so this will help by disabling indexing. Note that this might cause many of the smart features to stop working
- Use the command line. You don’t need an IDE to develop Android projects. You can just run
./gradlewin the project folder to build, package, and install the app. You can edit the source files in any text editor.
Solution 5: Stop whole computer crashes at OOM
Your whole computer should not crash when a program tries to use too much memory. It should only kill the most memory-hogging program.
- Install and properly configure
- If that’s not possible, disable swap