Android Studio error: Consider deleting _JAVA_OPTIONS

7.5k Views Asked by At

I am working on Kali Linux and wanted to get started with Android development and Flutter but I am getting this error after installing Android Studio:

The use of Java options environment variables detected. Such variables override IDE configuration files (*.vmoptions) and may cause performance and stability issues. Please consider deleting these variables: _JAVA_OPTIONS.

What does this mean and what can I do about it?

4

There are 4 best solutions below

0
On BEST ANSWER

This warning comes up because you have an environment variable called _JAVA_OPTIONS setup by default. On Kali Linux, this variable typically carries default formatting/encoding for your Java installation.

  • To view the value of this variable, use printenv _JAVA_OPTIONS.
  • To delete the value of this variable, use unset _JAVA_OPTIONS.

Once removed from your environment variables, Android Studio will no longer display the previous warning.

[Edit]: I noticed that after deleting the variable, Android Studio was now able to build projects that were previously failing to build.

NB: If you foresee a need for the variable elsewhere, you can copy it out and move it into your ~/.bashrc or ~/.profile (comment it with #) for later use.

0
On

I am using Kali Linux at the moment. The following command printenv _JAVA_OPTIONS works, but only temporarily. If you are interested in knowing why? Visit site link. Once you restart android studio the error pops up again.

Here's my workaround:

  • Open your bash terminal.
  • Unset the variable; printenv _JAVA_OPTIONS
  • Switch your current directory to that of your android studio launcher, usually in; android-studio/bin
  • Then launch your android studio; ./studio

Here's an elaborate example:

enter image description here

In my case, the error didn't pop up. The process seems tedious for every android studio launch but at least it works. I hope my answer helps the next victim.

The following script should make work easier. Just remember to make it executable by;

  • chmod +x <file_name.py>
  • The script:
  #!/usr/bin/env python3

  """Script to counteract _JAVA_OPTIONS error in android studio"""

  import subprocess
  import os


  def studio_launcher():
      """android-studio launcher"""

      # change dir to android-studio dir
      os.chdir('/opt/android-studio/bin')
      # execute launch
      subprocess.Popen(['./studio.sh'])

  me_status_code = os.system("printenv _JAVA_OPTIONS")

  #If printenv is successful
  if me_status_code == 0:
      print("We in")
      try:
          print("Try to unset")
          del os.environ["_JAVA_OPTIONS"]
          print("Unset successful")
          studio_launcher()
      except SystemError:
          print("Sth went wrong!!!")
          studio_launcher()
  else:
      print("Var empty!!")
      print(me_status_code)
      studio_launcher()
0
On

In response to @antony-kavoo. You can avoid re-doing the process by running the below command:

echo 'unset _JAVA_OPTIONS' >> $HOME/.zshrc

Note: if you are using bash, use $HOME/.bashrc

0
On

For windows

  1. Search for env.

  2. It will bring two options

    .Edit environmental variables for your account

    .Edit the system environment variable.

  3. Choose option two to edit the system environments.

  4. It will open a pop-up of System properties. where you will go to the Advanced settings tab.

  5. Bellow the tab you will find Environmental variables.It will also open another tab with

    .User variables

    .System Variables

  6. Go to the system variable. There you will find your _JAVA_OPTIONS path.

  7. Delete it and refresh your android studio. The error should be gone.