Millet Porridge

English version of https://corvo.myseu.cn

0%

Run VSCode Remote in Android

2020-11-05 update VSCode has already support aarch64, no more need VSCode Insiders

Original intention

Since VSCode added the remote ssh, it can separate interface and backend, and only need ssh protocol to connect backend, Recently, I had the idea that I could create an ssh port on my Android phone, and then use VSCode to run a server on my phone, When you go out, you can write and read code by connecting to Android, after all, the performance of the smartphone is good enough.

My phone is a OnePlus 7 Pro official system, not rooted.

Android sshd prepare - Termux

Termux is a lightweight, cross-platform, open source, cross-platform terminal emulator. I have introduced it in DevOps pains and the use of Termux, the termux could also start an OpenSSH server in the phone:

1
2
$ pkg install openssh-server
$ sshd

Use telnet to check the server.

After that, we need to create a ssh key-pair, or use the exist public key. You could use adb push to push the publish key to the phone, and then copy it to the authorized_keys.

1
2
3
4
5
6
$ termux-setup-storage
$ mkdir -pv ~/.ssh
$ cat /sdcard/id_rsa_raspberry.pub >> .ssh/authorized_keys
$
$ whoami # whoami, get the current user.
u0_a177

Then, you may connect the phone throught the terminal:

1
2
3
4
5
~ ❤  ssh u0_a177@10.249.131.26 -p 8022 -i ~/.ssh/id_rsa_raspberry

Welcome to Termux!

...

There is part of the ssh_config:

1
2
3
4
5
Host oneplus
User u0_a177
HostName 10.249.131.26
Port 8022
IdentityFile ~/.ssh/id_rsa_raspberry

First connection in VSCode

There is a problem aarch64 is only supported in VS Code Insiders

So, I use VSCode Insiders https://code.visualstudio.com/insiders/.

First connection in VSCode Insiders

There is another error that node can’t run:

I’m trying to use node to run js code, but I still got errors.

This time I guessed that the Android runtime library was missing some files, and I didn’t give up, and turned to look for containers on Android.

Containers in Android

I found a tool that can run containers in Android: https://github.com/nmilosev/anyfed. It uses proot, which means you don’t need root your Android phone.

You can notice it get a Fedora image.

  1. Setup the cpu arch

  1. Donwload the container

  1. Configure sudo and proot

  1. Try to start the container

You need:

1
2
$ unset LD_PRELOAD 
$ /data/data/com.termux/files/home/.anyfed/anyfed

There is no ssh in the anyfed, so we need to install openssh-server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@anyfed home]$ sshd
bash: sshd: command not found
[root@anyfed home]$ yum install openssh-server

# Rememober to modify the sshd_config, you can't use 22 as sshd port, this time I use `8122`
[root@anyfed home]$ vi /etc/ssh/sshd_config

# Create host key
[root@anyfed home]$ /usr/sbin/sshd
[root@anyfed home]$ ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
[root@anyfed home]$ ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
[root@anyfed home]$ ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

# Copy publich key to the authorized_keys
[root@anyfed home]$ mkdir ~/.ssh
[root@anyfed home]$ cp /data/data/com.termux/files/home/.ssh/authorized_keys ~/.ssh/

You need to create another ssh_config, and this time we use root user:

1
2
3
4
5
Host oneplus2
User root
HostName 10.249.131.26
Port 8122
IdentityFile ~/.ssh/id_rsa_raspberry
1
~ ❤  ssh oneplus2

Second connection in VSCode Insiders

It works!

I clone a repo in GitHub, use VSCode open it.

A notict to install Python extensions

Compare to the old laptop, the smartphone performance is better.

Conclution

VSCode actually give us a solution to use the idle resource in smartphone to develop. As the smartphone is more powerful, the performance is also better. I’m no doubt that one day the performance of the smartphone is good enough to allow us to develop on it. I’d like to combine VSCode and Frp as a solution to develop on Android smartphone.