Coding on an Android Phone
This is a follow-up / extension of my other post, Using the Cloud As Your Mobile Workstation, check it out if you haven't!
What This Post Is About
No this is not a tutorial to code an Android app
Last week I happened to be away from home all day and only left with an ultra-thin laptop to work on. The laptop's battery would not have lasted me the whole day if I ran my virtual machines. As I pointed out in my post above, my solution was using a cloud virtual machine as a workstation, because it was inexpensive for the amount of compute power you get running it for one day and it preserved my laptop's battery.
Today's post however, goes one step further, and details how you can work on your programming projects using an Android device.
Why Would You Want To Do This?
"...your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should."
In the current COVID-19 pandemic of 2020, many businesses and establishments do not offer their regular sit-in / walk-in spaces. So imagine my surprise when I went to drop off my car for a check-up only to find out it would take 2 hours instead of 20 minutes. And there was nowhere to sit. And I only had my phone on me.
"Why don't you go to the (fast-food place with a clown) down the road?"
Photo by Jonas Jacobsson on Unsplash
So there I was, sitting on the counter, sipping on my iced coffee and scrolling through social media all by myself, when a thought hit me: "why don't I work on my project?"
The How I Did It
The process is actually easier than you might think, and there are even software as a service platforms such as GitPod which offers a VSCode instance in a chrome browser. However, I was more comfortable using a command line and using short-cuts for VIM on a touch keyboard felt more natural than on VSCode. But how do I get a terminal on my phone?
Termux is an open source terminal emulator for Android, providing a sand-boxed Linux-like environment for you to access using a console interface. It doesn't require me to root my phone (which I couldn't have without another machine) and it was available on F-Droid. It's a truly wonderful project, and perfect for what I wanted to do.
Now, I wasn't about to install all my project dependencies on my phone. The bandwidth of public Wifi combined with my phone's battery would make sure I never finish setting up the project before my car was ready.
Instead, I just reused what I had in my last post: a cloud-based virtual machine to work on, but this time, with my phone as a thin client.
The Cloud, Round 2
Last time, I created a snapshot (a copy in time) of both the virtual machine with my development environment and the block storage with my project. The benefit of these snapshots is that I can just bring it back online and it will be the same as when I shut it down.
So after I generated my SSH key in Termux and uploaded it to my cloud provider, I recreated the virtual machine and SSH-ed in, and viola, a perfectly usable, and powerful, development machine.
How My Cloud Development Machine Looks In Termux On My Android Device
or is it?
There Is Always A But
I'm not going to lie to you and say that this was a perfect experience and that everyone should be coding on their phones. No no no, this was by far the worst experience short of using punched cards and a single-key keyboard to type in Morse code, plus at least those would be kind of fun.
Between the small screen real estate (without an external keyboard) and constant context-switching, it can be insufferable to work on for most people, me included. If I were to do it again though, a wireless keyboard would definitely help here.
If it's such a bad experience, why am I recommending it?
I would not say recommending but more so showing readers who have not explored the capabilities of their everyday devices that programming is possible on a wide array of electronics and not just a powerful desktop machine. In addition, I want this to be a motivation that you can, in fact, program on the go if you put your mind to it.
Next time I'll program on top of Everest or something
Follow or reach out to me on Twitter @justinhodev for my daily coding titbits!
If you're interested in the project I'm working on, here is the repository.