Writing kotlin / Java in vscode

Time:2021-3-18

Writing kotlin / Java in vscode

preface

I don’t want to start Android studio every time I run the code. It happens that vscode can be used as a lightweight IDE, so vscode is configured to write kotlin programs

Environment configuration

First, you can find kotlin compiler in the installation directory of Android studio
Writing kotlin / Java in vscode
Writing kotlin / Java in vscode
Add the following to the environment variable:
The value is: kotlin compiler pathbin
For example: D: program files Android studio plugins kotlinkotlinbin
Writing kotlin / Java in vscode
Then enter the command from the consolekotlinc -versionCheck whether the environment is properly configured
If it is normal, it is as shown in the figure below
Writing kotlin / Java in vscode
If that happens
Writing kotlin / Java in vscode
The reason is that the JDK version is not configured correctly or the Java environment is not configured correctly. You can reconfigure it (JDK1.8 is recommended)

Configure vscode

Install kotlin language and code runner in vscode extension
Writing kotlin / Java in vscode
Writing kotlin / Java in vscode
After installation, restart the loading extension, and then you can write kotlin code and compile and run it. Right clickRun CodeperhapsCtrl+Alt+NRun the program, OK, like this
Writing kotlin / Java in vscode
However, we found that the Chinese output panel appeared garbled, the feasible solution is to add a sentence in the user settings"code-runner.runInTerminal": true,, which means that if you let kotlin program run through terminal, there will be no Chinese garbled code
The results are as follows
Writing kotlin / Java in vscode
In addition, the corresponding jar package will be generated in the program directory, such as:
Writing kotlin / Java in vscode

summary

At this point, vscode about kotlin configuration has been completed

Enjoy Your Code!
2018/08/31