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:
Settings > System > About > Advanced System Settings -> Environment Variables:
Delete
JAVA_TOOL_OPTIONSvalues 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.
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) callingset JAVA_TOOL_OPTIONS=blahand 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 NEWVALUEdoes not need "=" sign.set VARNAME=NEWVALUErequires the "=" sign
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:
Settings > System > About > Advanced System Settings -> Environment Variables:
Delete
JAVA_TOOL_OPTIONSvalues 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.
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) callingset JAVA_TOOL_OPTIONS=blahand 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 NEWVALUEdoes not need "=" sign.set VARNAME=NEWVALUErequires the "=" sign
In terminal type; printenv to see environment variables. Scroll down slowly then you will see the _JAVA_OPTIONS Type; unset _JAVA_OPTIONS Then Type printenv lastly and you will not see it there anymore. Restart your pc before launching pycharm.
Videos
I tried setting this variable in my windows environment with Java 7 and doing java -version it gives me it set this variable , as shown as follows
C:\Users\ajduke>set JAVA_TOOL_OPTIONS=-Djava.net.preferIPv4Stack=true -Dfile.e
ncoding=UTF8
C:\Users\ajduke>java -version
Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF
8
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
Java HotSpot(TM) Client VM (build 21.0-b15, mixed mode, sharing)
In case only the first argument is picked up: DON'T USE QUOTES! Just the arguments:
set JAVA_TOOL_OPTIONS=-Xms128m -Xmx512m
In my case (Windows), only the first argument was picked up and reported to be invalid, since I used
set JAVA_TOOL_OPTIONS="-Xms128m -Xmx512m"
and starting any java app results in:
Picked up JAVA_TOOL_OPTIONS: "-Xms128m -Xmx512m"
Invalid initial heap size: -Xms128m -Xmx512m
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
You can use _JAVA_OPTIONS to pass options to any JVM process started on your system.
For example,
set _JAVA_OPTIONS=-Dsun.java2d.noddraw=true
When a JVM starts, it parses the value of _JAVA_OPTIONS as if the parameters were at the command line of java. You can see the passed parameters via JVisualVM.
For more information, read the blog post: What I discovered while trying to pass Default JVM Parameters
And according to https://bugs.openjdk.java.net/browse/JDK-4971166 undocumented Hotspot-specific _JAVA_OPTIONS was superseded by JAVA_TOOL_OPTIONS that is included in standard JVMTI specification, does better handling of quoted spaces and should be always preferred.
Since JDK 9+ there's also JDK_JAVA_OPTIONS as the preferred replacement, see What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?