A Guide to Setting up a Development Environment on Android Devices
Tags: Golang, Rust, Android, Programming, Python

Overview

Nowadays phones and tablets are getting more computing power, memory and storage. As developers, besides using the devices in our daily life or for developing mobile apps, in this guide I am going to show how you can turn your Android phone or tablet into a programming or development environment for Go, Node.js, Python and Rust, including setting up a Jupyter Notebook environment that you can use for data analysis and exploration. In practical you may not leverage this kind of setup on daily basis, but who knows it may be useful at certain occasions.

Getting Started

Termux

The only Android app that we need to install is Termux which provides an Android terminal emulator and Linux environment application that works directly with no rooting or setup required.

Once installed you should have an Android terminal emulator with bash shell.

Termux Terminal Session

Upgrade the packages by running

$ pkg upgrade

Hacker Keyboard

Since we will be using it for coding, I strongly suggest you install Hacker’s Keyboard.

Hacker’s Keyboard

Remote Access

For ease of illustration, I will be setting up remote access to the Android devices. There are multiple ways to do this. Below I will show you how to set up VNC server and OpenSSH.

Remote Access — SSH

Install OpeSSH

$ pkg install openssh

2. To make it simple I will use password authentication. The recommended way of logging in is using public key authentication.

Use the following command to find out the current user id. You need this for login later. In my case the id is u0_a196.

$ id

Reset the password for the current id

$ passwd

3. Start OpenSSH at port 8022

$ sshd -p 8022

4. Find out the IP address of your Android device using ifconfig command. In my case it is 192.168.0.116.

$ ifconfig

5. From you computer, install any SSH client to connect to the Android device. For macOS I just use the ssh command

# ssh -p 8022 u0_a196@192.168.0.116

And we should be able to login and see the Android terminal screen from the computer.

SSH Session to Android Device

Remote Access — VNC (Optional)

Enable the x11 repository

$ pkg install x11-repo

2. Install tigernvnc, xhost, i3 and aterm

$ pkg install tigervnc i3 aterm xorg-xhost $ xhost +

3. Start the VNC server and you will be prompted to enter a password.

$ export DISPLAY=":1" $ vncserver :1

4. If VNC server is started successfully, you will see the the following message, indicating VNC is is available on display localhost:1

New 'localhost:1 (u0_a196)' desktop is localhost:1 Starting applications specified in /data/data/com.termux/files/home/.vnc/xstartup

Log file is /data/data/com.termux/files/home/.vnc/localhost:1.log

4. Get the IP address of your Android device using ifconfig command. In my case the IP address is 192.168.0.116

$ ifconfig

5. Modify /data/data/com.termux/files/home/.vnc/xstartup to use i3 windows manager.

#!/data/data/com.termux/files/usr/bin/sh

## This file is executed during VNC server

## startup. # Launch terminal emulator Aterm.

# Requires package 'aterm'. aterm -geometry 80x24+10+10 -ls & # Launch Tab Window Manager.

# Requires package 'xorg-twm'.

i3-wm &

5. Restart VNC server

$ killall Xvnc $ vncserver :1

5. In your desktop or notebook, install tigervnc viewer. The VNC server port is 5900 + display number. In my case it is 5901

VNC Viewer

xterm on Android

Terminal Setup

Z Shell

The default shell is bash. For those who want to use Z shell

$ pkg install zsh $ zsh

Then you can proceed to install Oh My Zsh. In this article I will use the default bash shell for the remaining walkthrough.

Oh My Bash

Install Oh My Bash

$ pkg install git curl $ bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"

Development Environment Setup

git has already been installed when I installed Oh My Bash. Let’s continue to install the rest of the applications.

Python

$ pkg install python

Golang

$ pkg install golang

Rust

$ pkg install rust

Node.js

$ pkg install nodejs

tmux

$ pkg install tmux

$ git clone git://github.com/wting/autojump.git $ cd autojump $ ./install.py

Then proceed to add the autojump scripts to .bashrc and restart the terminal.

$ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf $ ~/.fzf/install $ source ~/.bashrc

terminal file manager — ranger and nnn

Install a terminal file manager. I installed nnn and ranger.

$ pkg install nnn ranger

$ pkg install ripgrep

$ pkg install fd

$ pkg install bat

I cover the essential utilities. There are many more that you can explore. For now let’s proceed to the next section.

Code Editor

I recommend either Neovim or Emacs. Both are great code editors. Visual Studio Code can also be used but require more steps to set up.

Neovim

$ pkg install neovim $ pip3 install pynvim

Emacs

$ pkg install emacs

Visual Studio Code

git, Node.js and python are required and have been installed in previous steps. Let’s install other required libraries

$ pkg install yarn build-essential

Install code-server . This may take awhile.

$ yarn global add code-server

Start code-server in the background and accept remote connection. This allows connection from the mobile as well as from remote computer.



10:19:31 u0_a196@localhost code-server → code-server --bind-addr 0.0.0.0:8088 &

10:19:41 u0_a196@localhost code-server →

10:19:42 u0_a196@localhost code-server →

10:19:43 u0_a196@localhost code-server →

10:19:44 u0_a196@localhost code-server →

10:19:44 u0_a196@localhost code-server → [2020-12-20T02:19:49.227Z] info code-server 3.8.0 c4610f7829701aadb045d450013b84491c30580d

[2020-12-20T02:19:49.232Z] info Using user-data-dir ~/.local/share/code-server

[2020-12-20T02:19:49.277Z] info Using config file ~/.config/code-server/config.yaml

[2020-12-20T02:19:49.278Z] info HTTP server listening on

[2020-12-20T02:19:49.278Z] info - Authentication is enabled

[2020-12-20T02:19:49.278Z] info - Using password from ~/.config/code-server/config.yaml

[2020-12-20T02:19:49.278Z] info - Not serving HTTPS [1] 3242110:19:41 u0_a196@localhost code-server →10:19:42 u0_a196@localhost code-server →10:19:43 u0_a196@localhost code-server →10:19:44 u0_a196@localhost code-server →10:19:44 u0_a196@localhost code-server → [2020-12-20T02:19:49.227Z] info code-server 3.8.0 c4610f7829701aadb045d450013b84491c30580d[2020-12-20T02:19:49.232Z] info Using user-data-dir ~/.local/share/code-server[2020-12-20T02:19:49.277Z] info[2020-12-20T02:19:49.278Z] info HTTP server listening on http://0.0.0.0:8088 [2020-12-20T02:19:49.278Z] info - Authentication is enabled[2020-12-20T02:19:49.278Z] info - Using password from ~/.config/code-server/config.yaml[2020-12-20T02:19:49.278Z] info - Not serving HTTPS

The configuration is in ~/.config/code-server/config.yaml

10:11:12 u0_a196@localhost code-server → cat config.yaml

bind-addr: 127.0.0.1:8080

auth: password

password: a46e0940a161e9a1b2b639a8

cert: false

From browser, connect to code-server at port 8088 and enter the password.

Visual Studio Code on Android

Code Editor Setup

Let’s set up the code editor. Since both Neovim and Emacs are highly customisable, you may not necessary need to follow the setup described below.

Alternatively for vim/neovim you can use Vim Bootstrap to generate .vimrc or init.vim of your flavor. For Emacs you can use Emacs Bootstrap.

coc.nvim requires Node.js so let’s install it if you haven’t.

$ pkg install nodejs

init.vim to demonstrate language support for python, golang and rust.

init.vim

Neovim with Python

Neovim with Golang

Neovim LSP

Neovim also supports LSP without using coc.nvim. I will go through this setup in another article.

Emacs

I will go through Emacs LSP and DAP setup for Python, Golang and Rust in other articles.

Remote Code Development

For remote code development, check out this article.

Setting up Jupyter Notebook

Lastly, let’s also set up Jupyter Notebook.

Install jupyerlab.

$ pip install --upgrade pip $ apt install clang python fftw libzmq freetype libpng pkg-config $ LDFLAGS=" -lm -lcompiler\_rt" pip install jupyterlab

Start jupyterlab which accepts remote connection.

$ jupyter-lab --ip="0.0.0.0"

juypter-lab