Search code examples
javaandroid-studioenvironment-variableswindows-10javaoptions

The use of Java options environment variables detected. How to delete it?


When I turned Android Studio on Windows 10, I got this warning:

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_TOOL_OPTIONS.

So, I want to delete this variable, but I don't know how. This similar query didn't help me because I don't see this variable in system variables. I suspect I must have set it via the command line when I was troubleshooting another issue. When starting the console of any IDE, the message:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8

Is also displayed. Can it be deleted somehow?


Solution

  • As mentioned in the other questions, you get that warning if starting any java process when the JAVA_TOOL_OPTIONS environment variable is declared. This is mentioned in Windows Android Studio logs on start-up, and also if you run java -version from a terminal / cmd.exe.

    Before removing first check whether you need these addition settings or not. The setting -Dfile.encoding=UTF8 is default for JDK19 onwards, but not for earlier JDKs and fixing to avoid an Android Studio warning might cause unexpected changes elsewhere with other Java based applications on pre-JDK19.

    Two places I know where it could be defined:

    1. Settings > System > About > Advanced System Settings -> Environment Variables:

      Delete JAVA_TOOL_OPTIONS values under your user settings or System settings.

      This setting can be added back by re-entering in the dialog or typing command: setx JAVA_TOOL_OPTIONS blah.

      Don't forget to close/re-open Windows Terminal or CMD.EXE after making changes to the environment variables or they won't see the new values.

    2. As a local variable in CMD.EXE. This setting may have been added by some init script (say if you use CMD.EXE /k init.cmd) calling set JAVA_TOOL_OPTIONS=blah and this overrides / replaces 1) value.

      You may be able to remove with set JAVA_TOOL_OPTIONS= and re-running java or Android Studio from that CMD, but note that the original value will be restored after close/re-open CMD if it was set in 1) already.

    There is no doubt an easier way to do this as annoyingly it adds a blank cmd terminal: if you wished to disable for just Android Studio you could set up an alternative windows shortcut with this as "Target" field (do no add any extra spaces):

    cmd.exe /c set JAVA_TOOL_OPTIONS=&&"C:\Program Files\Android\Android Studio\bin\studio64.exe"
    

    Note:

    • setx VARNAME NEWVALUE does not need "=" sign.
    • set VARNAME=NEWVALUE requires the "=" sign