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.
~/.config/Google/AndroidStudio20*/studio64.vmoptions
-Xmx*
(like-Xmx4096m
) with lower values such as-Xmx2048m
-Xms
to the same valueSolution 2: Lower Gradle's JVM's max memory
You can have Gradle use less memory when building projects.
~/.gradle/gradle.properties
org.gradle.jvmargs=-Xms1G -Xmx1G
kotlin.daemon.jvmargs=-Xms1G -Xmx1G
gradle.properties
in any Android project you are working in before opening them, to avoid them overriding the above settingsSolution 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 usesystemd-run
.systemd-run --user --scope -p MemoryMax=2G bash
~/.local/share/JetBrains/Toolbox/apps/android-studio/bin/studio.sh
or wherever you installed itSolution 4: Reduce Android development resource consumption
There are other tips you can use while developing Android projects:
./gradlew
in 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.
systemd-oomd