Coding on Android using VS Code
Before Apple introduces the M1 chip which is based on the ARM architecture no one really understood how powerful the small processors that we have in our cellphones and tablets have become but now that we know, can we use them for more than what they already offer? Yes.
It is some years that Samsung has introduced its Dex technology that enables Galaxy users to use their phones as a desktop by connecting them to an external display. Recently and from Android 10 Google also added the “desktop mode” to android (although you need to activate the developer mode first) which enables any Android device with Android 10 to be used as a desktop by connecting to an external display.
So we have small devices with powerful CPUs that can become a full desktop anytime we want so why we are not coding on them? We should and we can and here I will show you how to do it.
For this we need three things:
- Termux
- Ubuntu on Termux (Via Andronix)
- VS Code
Installing Termux
Termux is a terminal emulator for Android with different packages. Those packages will be compiled with Android NDK and will be executed natively. More information can be found at Termux FAQ.
You can install Termux directly from the Google play store.
Installing Ubuntu on Termux
For installing Ubuntu on Termux you need another android application called Andronix. Andronix provides and installs different Linux distros and here we use Ubuntu.
Steps to install Ubuntu:
1. Install Andronix from the Google play store
2. Follow the instructions at Andronix documentation on how to install Ubuntu
Installing and running the VS Code
1. open Termux
2. Launch Ubuntu by running: ./start-ubuntu
3. Download and extract the code-server by running:
# find the link for the latest LINUX-ARM64 version of code-server (or any other LINUX-ARM64 version that you need) from https://github.com/cdr/code-server/releaseswget https://github.com/cdr/code-server/releases/download/v3.8.0/code-server-3.8.0-linux-arm64.tar.gztar -xvf ./code-server-3.8.0-linux-arm64.tar.gz
4. Install code-server:
cp ./code-server-3.8.0-linux-arm64/code-server /bin
5. Launch VS Code: code-server
After launching the VS Code you need to go to a browser in your android device and go to the http://localhost:8080
or the URL that you see in the logs of the code-server.
You also need to copy the password from the logs of the code-server so you can log in to VS Code.
After you logged in you will see the VS Code and you can use it exactly like a normal VS Code.
Configuring code-server password
You can set the password that you want so every time you won’t need to copy and paste the generated password from the logs of the code-server. To do this you need to set an environment variable as below and then launch the VS Code:
export PASSWORD=”YOUR_PASSWORD”
code-server
If you want you can use the --auth none
flag when launching code-server to disable the password.
Practical points
Termux provides an environment almost equal to a full Linux machine on android therefore for using different programming languages either from the Termux terminal (after launching your Linux distro) or from the VS Code terminal you can install different programming languages, libraries and packages that you need, for example, I installed the git from the VS Code terminal just by running apt install git
and then cloned a repo.
Please be aware that in Termux you are working as the `root` user and you don’t need to use `sudo`.
Buy me a coffee: https://www.buymeacoffee.com/avarf