Command-Line based Development Environments for Building and Debugging Android Applications
Summarized -- Based on the original question and the request of the bounty benefactor, this post shall elucidate:
- How to create an Android project from Command-Line Interface (CLI), with the correct directory structure?
- How to establish a CLI based development environment for building and debugging Android applications?
1. Creating Android Projects
Firstly, one has to note, that the exact structure of an Android project mostly depends on the used IDE, e.g. Android Studio, Eclipse, IntelliJ, and the build systems it supports, e.g. Gradle, Maven, Ant. However nobody is forced to use any of these. In contrary, one doesn't need to use any of them, as I explained and applied in my article "Mobile Development: APK Building on Mobile".
So there is actually no "correct" physical structure for an Android project, only a logical one like depicted in Fig.1.
Fig.1. Logical structure of an Android application project
Nevertheless one can assume, that one would want to create an Android Studio alike project structure. Alas, as pointed out in the Android Development Documentation for the android
tool, and discussed in the Stackoverflow thread "How to create an Android project from the command line", the once for this purpose provided android
tool has become deprecated and isn't part of the official command-line tools anymore. All its functionality has been delegated to other tools. The automatic creation of Android projects is now done using Android Studio itself, as the official documentation says.
So for that there's no replacement on the CLI for now. One would have to create such kind of a project structure manually, or copy an existing Android Studio project as a basis.
2. Establishing a CLI based Development Environment
2.1. On Linux, Windows and MacOS
The Android Developer Documentations on the Android SDK Command-line Tools and the corresponding Release Notes are the first addresses for the documentation of the tools, considering setup, usage options and further notes.
The basic steps to setup a CLI based APK development environment are as follows.
- Set the environment variables as described in the documentation.
- Download the
cmdline-tools
, which include core tools as sdkmanager
to manage the SDK components, avdmanager
for emulators, as well as debugging and tuning tools like r8
and lint
.
- Use
sdkmanager
to install the following packages:
build-tools
-- Contains basic toolchain programs like aapt
, apksigner
, and d8
.
platforms
-- Contains the Android platform, i.e. API level, you want to develop for. Note, that you can use several platforms in parallel at need.
platform-tools
-- Contains instruments, e.g. the important adb
, that interface with the corresponding Android platform. Choose the platform-tools
according to the before selected platforms
packages.
ndk
-- Needed for performant native programming.
- Use
avdmanager
to manage the Android device emulators of the Android SDK.
- If required, also install
gradle
according to the Installation guide. Gradle can then be used from CLI, as described in its Command-Line Interface user guide.
2.2. On Android
One can actually develop mobile applications right on a mobile device. Therefore one has to install the terminal emulator Termux on it. Installation and usage don't need rooting of the device. Its repositories provide packages for many purposes, inter alia all necessary tools for APK building.
Then there are two approaches to achieve a CLI based development within Termux.
One is to achieve essentially the same setup as on a desktop, like described above, by following meticulously this guide. Note, that this will need at least 6GB free storage, easily up to 10GB and more, on your mobile device.
Another is to use the free APK building tool apkbuilder
. It is my slim solution which requires all in all, so with all necessary components, less than 800MB, and no further configuration. Works without restrictions considering the project's structure and complexity. Supports also projects using native C/C++ code besides Java. Kotlin support is envisaged for the next version. The complete guide for installation and usage is located here.
Epilogue
Several roads lead to Rome. Free available tools allow a purely CLI based development of Android applications both in desktop environments, and even on mobile devices themselves. Have fun!