4 minute read

One of my favorite features of Samsung smartphones is DeX, an Android-based desktop environment available when the phone is connected to an external monitor. Though DeX can be used to get more screen real estate for watching videos or running apps, I’ve recently begun using it as a minimal but functional coding environment.

In this post, I’ll walk through a basic Linux-like development setup and talk about my opinions at the ends.


Developing cosmotop on DeX

Hardware and DeX

Unsurprisingly, Samsung DeX requires a Samsung device, not just any Android. I’ve tested on a Samsung Galaxy phone, but Samsung tablets should also work.

For DeX to activate, you will need an external monitor and a USB-C cable capable of transmitting video signal. The USB-C cable connects to the phone, and the other end connects to the monitor. When the phone is plugged into a display, the DeX desktop will show up on the monitor, and the phone turns into a touchpad for mouse controls.

When connected to a portable USB monitor, the phone can act as a power source and power the monitor through the cable, though at the cost of faster battery drain. For advanced usage, a laptop USB-C docking station or hub with support for monitors also works, and can also provide power back to the phone to charge it while in use. However, multi-display docks will not provide an extended desktop, instead mirroring a single desktop on all screens. The dock can also provide extra USB ports, which can handle useful peripherals like a physical keyboard and mouse.

Installing Termux

To get a Linux environment on the phone, we will use the Termux app and proot-distro to install a full Debian distribution. This will allow us to download and install Visual Studio Code and access it through the browser.

To install Termux, get the app from F-Droid. The Google Play Store version is not recommended.

Configure Termux to access the phone’s storage with the following command. This will be used to download and install Visual Studio Code later.

termux-setup-storage

WARNING: Setting up software can involve downloading a large amount of files. Ensure your device is connected to Wi-Fi to minimize data charges.

While Termux provides a usable Linux environment, a more complete distribution can be installed with proot-distro. Install proot-distro and Debian as follows:

pkg install proot-distro
proot-distro install debian

NOTE: For other available Linux distributions, run proot-distro list.

Once complete, a root shell can be launched in the distribution:

proot-distro login debian

Installing Visual Studio Code

To install Visual Studio Code, get the .deb package for Linux Arm64 from this page. Inside the proot-distro shell, update apt and install the package.

apt update
# Note: Your downloaded file name may differ
apt install /data/data/com.termux/files/home/storage/downloads/code_1.102.0-1752099871_arm64.deb

Sit back for a few moments and let the install finish.

NOTE: If your downloads folder is inaccessible, ensure you have set up Termux’s access to your phone’s storage with termux-setup-storage outside of proot-distro.

Once completed, run Visual Studio Code in browser mode. This will allow you to use it through a web browser, without the need for a graphical environment within Termux.

DOTNET_GCHeapHardLimit=0x400000000 code serve-web

NOTE: In this command, a dotnet environment variable is set to ensure that Visual Studio Code extensions can be installed correctly. More specifically, the program that verifies extension checksums relies on dotnet, and will crash without setting this memory limit.

The command will output a localhost url, containing a token query parameter. Copy the entire url and open it in the browser.


Running Visual Studio Code through the browser on DeX

That’s it! You can now access the shell, install extensions, and write code.

Is it worth it?

While doing some limited coding via DeX is doable, I would not recommend ditching your primary development machine for the latest Galaxy smartphone. At the end of the day, though Termux and proot-distro provides a level of compatibility with traditional Linux distributions via emulation, DeX still operates under the limitations and restrictions imposed by unrooted Android. For example, access to system paths such as /proc and /sys is limited, and the performance hit of proot is noticeable when running Visual Studio Code in more complex repos. Running a few C++ compilation jobs in parallel can also cause Termux to exit, likely due to high resource usage.

Additionally, using the phone as a touchpad instead of a dedicated mouse can be a challenge to get used to. For example, scrolling on the touchpad can cause Chrome’s navigation bar to show and hide, which can be disorienting when compared to a fixed bar when scrolling on a traditional desktop. The virtual keyboard also sometimes pops up when text entry widgets are focused, even if a physical keyboard is present. Though the virtual keyboard goes away when something is typed on the physical keyboard, the virtual keyboard makes it difficult to swipe on the touchpad and can lead to unintended extra letters typed.

Despite these challenges, I have been able to develop C++ applications and use Intellisense and GitHub Copilot through the Visual Studio Code setup. Some parts are slow, but in general, DeX is usable - in fact, this entire blog post was written through this setup! I would treat it as a last-resort setup for coding and certainly not a replacement for developing on a proper laptop or desktop.