Monthly Archives: November 2018

Workaround for IntelliJ and Android Studio crashing silently

Published / by Steve

Back in April I installed IntelliJ on a development machine, only to encounter a show-stopper problem: it would silently crash when I launched it, shutting down without providing a useful error message.

This happened on three different laptops. All were running Ubuntu 16.04 with Trinity Desktop Environment R14.0.5. (The exact versions have changed over time.)

Since IntelliJ is a commercial product, I posted a message in their forum: IntelliJ won’t start up. The issue was not resolved, and the only workaround was to start IntelliJ with sudo. I didn’t consider that an acceptable workaround; in addition to the obvious security risks, applications that create files when run with sudo can set permissions that become a hassle when not using sudo.

So I just didn’t use IntelliJ for a number of months.

Recently I needed to run Android Studio, and found it exhibited the same behavior. I wasn’t that surprised since it’s based on IntelliJ. However I didn’t have an easy substitute.

So I revisited the problem, asking myself what else was different when run with sudo that might cause this? One possibility was environment variables. It didn’t seem that likely, but it was easy to see the differences by comparing the output of ‘env | sort’ with ‘sudo env | sort’. It turns out there were many differences; regular env has at least twice as many environment variables set. So I started unsetting them. There were so many it got tedious and I started doing them in groups. Here I finally caught a break: unsetting the GTK* environment variables allowed Android Studio to start successfully, and there were only 4 of them.

From there it was straightforward to narrow it down to one variable: GTK2_RC_FILES. With this unset, Android Studio starts up.
Here is what mine has:
GTK2_RC_FILES=/home/scorwin/.gtkrc-2.0-kde4:/home/scorwin/.trinity/share/config/gtkrc-2.0

For the record, here are the file contents. I believe the contents are the defaults unchanged from the Trinity installation.

$ cat /home/scorwin/.gtkrc-2.0-kde4
  # This file was written by TDE
  # You can edit it in the Trinity control center, under "GTK Styles and Fonts"

  include "/usr/share/themes/Qt/gtk-2.0/gtkrc"

  style "user-font"
  {
          font_name="Tahoma 10"
  }
  widget_class "*" style "user-font"

  gtk-theme-name="Qt"
  gtk-font-name="Tahoma 10"
$ cat /home/scorwin/.trinity/share/config/gtkrc-2.0
# created by TDE, Thu Oct 18 13:36:41 2018
#
# If you do not want TDE to override your GTK settings, select
# Appearance & Themes -> Colors in the Control Center and disable the checkbox
# "Apply colors to non-TDE applications"
#
#
style "default"
{
bg[NORMAL] = { 0.918, 0.914, 0.910 }
bg[SELECTED] = { 0.663, 0.820, 1.000 }
bg[INSENSITIVE] = { 0.918, 0.914, 0.910 }
bg[ACTIVE] = { 0.765, 0.761, 0.757 }
bg[PRELIGHT] = { 0.918, 0.914, 0.910 }

base[NORMAL] = { 1.000, 1.000, 1.000 }
base[SELECTED] = { 0.663, 0.820, 1.000 }
base[INSENSITIVE] = { 0.918, 0.914, 0.910 }
base[ACTIVE] = { 0.663, 0.820, 1.000 }
base[PRELIGHT] = { 0.663, 0.820, 1.000 }

text[NORMAL] = { 0.000, 0.000, 0.000 }
text[SELECTED] = { 0.012, 0.012, 0.012 }
text[INSENSITIVE] = { 0.765, 0.761, 0.757 }
text[ACTIVE] = { 0.012, 0.012, 0.012 }
text[PRELIGHT] = { 0.012, 0.012, 0.012 }

fg[NORMAL] = { 0.000, 0.000, 0.000 }
fg[SELECTED] = { 0.012, 0.012, 0.012 }
fg[INSENSITIVE] = { 0.765, 0.761, 0.757 }
fg[ACTIVE] = { 0.000, 0.000, 0.000 }
fg[PRELIGHT] = { 0.000, 0.000, 0.000 }
}

class "*" style "default"

gtk-alternative-button-order = 1

style "ToolTip"
{
bg[NORMAL] = { 1.000, 1.000, 0.863 }
base[NORMAL] = { 1.000, 1.000, 0.863 }
text[NORMAL] = { 0.000, 0.000, 0.000 }
fg[NORMAL] = { 0.000, 0.000, 0.000 }
}

widget "gtk-tooltip" style "ToolTip"
widget "gtk-tooltips" style "ToolTip"

style "MenuItem"
{
bg[PRELIGHT] = { 0.663, 0.820, 1.000 }
fg[PRELIGHT] = { 0.012, 0.012, 0.012 }
}

class "*MenuItem" style "MenuItem"

I don’t know why this environment variable causes a problem. The value and the file contents seem safe enough. Hopefully someone more familiar with the Android Studio source code will figure it out.

For now I’ve created simple scripts that let me run both programs.
Workaround script for Android Studio:

$ cat ./myStudio.sh
#!/bin/bash
unset GTK2_RC_FILES
/home/scorwin/apps/android-studio/bin/studio.sh

Workaround script for IntelliJ:

$ cat myIdea.sh
#!/bin/bash
unset GTK2_RC_FILES
/home/scorwin/apps/idea-IU-182.4505.22/bin/idea.sh

Those scripts work from the command line, and after I created menu items for them, they work from the menu too.