Compile into APK on an Android device

If you want to edit or create some Android application, but you don’t have any computer immediately available, this article will explain you how to compile, on your tablet/smartphone, an Android Java application into a running APK that you can install straight away on the very same device where you just compiled it.

Introduction: alternative Android development practices

If you look at most, if not all, tutorials about how to develop an Android application, you will most likely read that Android applications are developed on a linux or windows computer, with an IDE such as Android Studio, NetBeans or Eclipse.

Of course, these are the preferred way to develop applications for Android, because they make a lot of things easier (by providing templates, auto-completions, smart compilation process…). But you may not have such IDEs available on your computer, may be because it is too old, has an unsupported distro, or because you just don’t like IDEs and prefer VIM (I approve !). Then, you will google for methods to develop Android applications from the command line, and you’ll most likely find some nice gradle or ant tutorial. Perfect, I encourage you to follow these methods: they’re nearly as good as the IDEs, in my opinion.

But there is still another situation, where you don’t have any computer at hand !

This article handles this case, and show you how to develop for Android from Android, using only free and open-source tools, and mostly the command-line. Before proceeding further, note that if you are not found of terminals, and if you are happy paying some bucks, you may rather use some Android development app available on the PlayStore, such as AIDE, which also gives you the possibility to develop on your tablet. I actually encourage you to start trying these apps, which nearly always offer some free starting option that lets you write a few very basic applications and test them. These options are good to make your mind about Android development and get your started with it, but when you’ll want to write some serious code, then you’ll have to pay. If you don’t want to pay or if you don’t want to use Google Services or connect to the playstore, then please go on reading !

What you need

  • An android tablet or smartphone, optionally (but strongly recommended !) with: a large enough SD card, a bluetooth keyboard. If you don’t have a hardware keyboard, I strongly recommend you to install the Hacker’s keyboard application, which provides keys that you will need (control, tab…).
  • Install the application Termux, which provides a rich linux-like terminal environment you will use to compile your applications.
  • A text editor: I strongly recommend VIM, which you may install within termux with
apt update
apt install vim

Tutorial update

This tutorial used to be quite longer, because in 2016, no integrated solution was available. But it’s now much easier, as other devs have worked from within termux to make this whole process easier, and I admit they’ve done a pretty good job at it !

So I’ve deleted the rest of my old hacky tutorial, and from there on, I just strongly recommend you to have a look at this repository on github, where you’ll find everything you need to build APKs from within termux:

https://github.com/sdrausty/buildAPKs

Happy dev !

Written on July 30, 2017