How to Code on Your Android Phone
Coding on an Android phone may appear challenging, but it's achievable. Thanks to technological advancements and the collaborative open-source community, coding on Android is now as practical as coding on a desktop computer.
There are numerous available ways to code on an Android phone. These range from web-based code editors like CodePen or GitHub Codespaces via VS Code for the web to Android applications such as TrebEdit, Replit, or ALIF's Code Studio, as well as terminal emulators like Termux. However, each option has its advantages and disadvantages.
This guide will explore how to utilize two of these options – Code Studio and Termux, why to use them, their pros and cons, and how to set them up correctly.
Using Code Studio
Code Studio is an IDE for developing Android apps, Java console programs and websites on an Android device.
Why use it
Code Studio is a good option for coding on Android because it has a ton of cool features that you'd want in an IDE. It's got features like syntax highlighting, auto-completion, and real-time error checking. Additionally, it supports multiple programming languages, like C#, Dart, and even Lua, making it versatile for different coding projects. Its got a user-friendly interface and customizable settings which further enhances the coding experience on an Android device.
Pros
Freemium and ad-free
User-friendly interface that's easy to use
Great for building and testing Android apps as well
Cons
Limited support for programming languages
No support for Git
How to set it up
Setting up Code Studio is pretty easy
Simply search for “code studio” on Google Play Store
Download it, and you’re ready to go
Using Termux
Termux is an Android terminal emulator and Linux environment app.
Why use it
Termux is an Android coding option for developers who want to go above and beyond. It provides a Linux-like environment with a powerful command-line interface that allows users to run Linux commands, install packages, and set up development environments directly on their Android devices. This makes it an excellent choice for developers who prefer working with command-line tools or need access to a wider range of programming languages and development tools than what's typically available on other Android coding options.
Pros
Provides a full Linux environment on Android
Access to a wide range of programming languages and tools
Highly customizable and flexible
Free and open-source
Cons
A steep learning curve, especially for those unfamiliar with command-line interfaces
Resource-intensive on older or low-end devices
Limited graphical user interface
How to set it up
Setting up Termux can be a bit complex, but here's a step-by-step guide to get you started
Downloading Termux:
You can download Termux directly from Google Play Store or download the APK from F-Droid
Open the app and wait for the initial setup to be completed
Setting up Git and GitHub:
Install Git by running the command
pkg install git
Set your username and email with
git config --global user.name "Your Name"
andgit config --global user.email "your@email.com"
Use
ssh-keygen -t ed25519 -C "your@email.com"
to create an SSH key. The SSH key will be used to securely connect your device to your GitHub account. After running this command, you’ll be asked to enter a location to save the file. Hit enter to pick the default location, then follow the remaining prompts.
Run
eval "$(ssh-agent -s)"
andssh-add ~/.ssh/id_ed25519
to start the SSH agent.Run
cat ~/.ssh/id_ed25519.pub
to open and copy the public key.
Add the SSH key to your GitHub account
Go to GitHub.com
Navigate to Settings > SSH and GPG keys
Click "New SSH key"
Paste your public key and save
Now you can work with Git and GitHub from Termux, clone repositories, make changes, commit, and push your code directly from Termux, giving you a great Android development setup.
Installing a programming language:
Once you have set up Git, you can install your preferred programming language. For example, to install Python, you can run the command pkg install python
in Termux. This will download and install Python on your device just as you would on a desktop computer. After installation, you can begin coding in Python directly from the Termux command line. Additionally, you can install extra Python packages using pip, similar to how you would install them on a desktop computer.
Editing Code:
There are several options for editing code in Termux. One popular option is the Nano text editor, which comes pre-installed. To use it, type nano filename.py
to create or edit a Python file. For more advanced users, Vim is another powerful option that can be installed with pkg install vim
. These editors allow you to write and modify your code directly within the Termux environment, providing a seamless coding experience on your Android device.
Basic Termux commands:
Here are some essential Termux commands to get you started
Create an empty file -
touch fileName.extension
Create a file with content -
echo 'content' > fileName.extension
Create a folder -
mkdir folderName
Open file -
nano fileName.extension
orvim fileName.extension
Copy file -
cp fileName destinationDirectory
Copy folder -
cp -r sourceDirectory destinationDirectory
Delete file & folder -
rm fileName.extension & rm -rf folderName
Move file & folder -
mv sourceDirectory destinationDirectory
Print working directory -
pwd
Install package -
pkg install packageName
Check package version -
package version
Update all packages -
pkg update
Uninstall package -
pkg remove packageName
With these basic commands, you can now navigate and manage files in the Termux environment. For more information on Termux and its commands, refer to the official Termux documentation or community forums. These resources provide comprehensive guides, tips, and advanced usage examples to help you make the most of this powerful Android development environment.
Summary
Keep in mind that coding on your phone has some limitations compared to coding on a desktop. The smaller screen size and touch interface can make certain tasks more challenging. However, with some practice and the right tools, coding on your phone can be very useful, especially when you're on the go or don't have access to a laptop. Whether you prefer Code Studio for its user-friendly interface or Termux for its powerful Linux environment, these tools can help you stay productive and keep coding even when you're away from your desktop computer.
Subscribe to my newsletter
Read articles from Ebenezer Raphael directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ebenezer Raphael
Ebenezer Raphael
I’m an upcoming web developer and technical writer.