iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💨

Developing on Android with Termux

に公開
2025/05/21

Introduction

Recently, I heard that even elementary school students are learning programming at school. Since there was no such thing in my day, I don't know exactly what they are learning. However, I remembered that back when I was in elementary school, I didn't have any devices I could use freely... and I decided to look up what kind of devices today's elementary school students who want to program are using.

https://www.moba-ken.jp/project/children/kodomo20240129.html
https://edtechzine.jp/article/detail/9768
https://www.cfa.go.jp/policies/youth-kankyou/internet_research/results-etc/r05

It seems that smartphones are the most common personal devices. Even so, it's only about 40% of upper elementary school students (reaching the alphabet around middle elementary school). As for PCs, it's less than 20%, so it doesn't seem to be a very free programming environment.

This is similar for junior high school students, where smartphones exceed 80% but PC penetration remains low.

There are devices lent by schools, but even that is not 100%. Personally, I am against teaching programming to elementary school students in schools, but I am all for them having an environment they can use freely if they wish. It doesn't have to be the latest; a cheap second-hand one is fine...

Therefore, this time I've thought a bit about a programming environment using only Android, which seems to have a relatively high ownership rate.

Android Development Environment

When I say "Android development environment," I am not talking about the environment for developing Android apps on a PC that you find when searching the internet. It is strictly an environment where you can develop using only an Android device.

Android development environments can be broadly divided into:

  1. Creating dedicated programs that run on specific Android apps
  2. Creating real Android apps that appear on Google Play

There are two types.

Regarding 2, honestly, it's tough unless it's a development environment on a PC, so this time I've only looked into type 1. However, instead of just running on a specific app, I'll choose a development environment where you can develop CLI programs that also run on PCs or other servers. In principle, this means they are not GUI.

Termux and UserLAnd

When it comes to "environments where you can create dedicated programs that run on specific Android apps," if I were to choose based on my own dogmatism and prejudice, I would say Termux and UserLAnd. Both are open development environments with public source code, and both are environments for developing and running mainly CLI programs like Linux.

UserLAnd is slightly more Linux-oriented, and I have the impression that it is difficult to directly touch Android-specific features (NDK). On the other hand, its structure is close to Linux, so people familiar with Linux might find it easier to develop. However, being UserLAnd, not all functions work perfectly, and it feels like they've cleanly given up on things that can't be done.

Termux has its quirks in operation, but it includes clever features to make it easy to use on Android alone, and there is little stress in default key input operations. It also has the advantage of being able to directly touch the NDK, and it is characterized by the ease of applying rough symptomatic treatments rather than building things generically according to Linux-specific conventions. This allows for "dirty" workarounds, which can be worrying, but having this option can be quite significant when you are forced to solve problems on your own without relying on anyone. Also, because it's not bound by Linux-specific conventions, it's somewhat lighter in operation. For the main differences from Linux, this article (English) is well summarized.

I previously wrote an article on Qiita (though it's gone now because I was banned) about how I felt when I was actually using UserLAnd myself, so I'll put a link to the original Markdown here for reference.

From the above, this article will use Termux (Termux is also more famous in terms of popularity).

Installing Termux

Actually, there are currently two ways to install Termux.

  1. Installing the Termux app available on Google Play (only for Android 11 and later)
  2. Installing F-Droid and then installing Termux from there

Only method 2 has official Termux support. However, method 2 does not reflect Google's security checks. Those confident in their skills should use method 2 without hesitation, but it's a difficult choice for children who have no financial freedom even if they were to take responsibility. Therefore, in this article, we will choose method 1 for (formal) safety. I don't think there's a huge difference from a development perspective.

https://play.google.com/store/apps/details?id=com.termux&hl=ja

If you use Google Play, just install and launch it like any other app.

Once launched, you'll see a screen with only text on a black background, and from then on, everything must be done via text input operations.

~ $ exit⏎

Note: The ⏎ symbol will not be included from here on.

To exit, you can either execute the exit command from the command line as shown above, or press exit in the notification area.

Termux is different from ordinary apps; you enter commands via text input and execute them. And that is all it can do. The commands you can run can be newly downloaded and installed as packages, or created by yourself.

The set of commands included right after installing Termux is a bit outdated, so when you first launch it, update them using the pkg command.

~ $ pkg update && pkg upgrade -y

If you are asked anything, just press ⏎ and it will be fine.

It's a good idea to run updates whenever you feel like it from then on.

Detailed Articles

GitHubで編集を提案

Discussion