Setting Up an Android App Development Terminal Workflow on Linux

You’ll have to drag me by my feet as I dig my nails into the floor, kicking and screaming if you ever want to make me use an IDE. I firmly believe that IDEs are bloat and more often than not get in my way. Believe me, I’ve tried putting up with them, but I just can’t.

The “Why?”

Don’t get me wrong, I think that IDEs are great for beginners. I remember writing my first lines of C++ code in Code::Blocks as a child. I simply think that IDEs are just not right for me as an advanced-level programmer, but that’s not to say that there aren’t people for whom IDEs are valuable tools for. I’m simply just of a different philosophy: I believe that when something bad happens, it should be my fault, not my software’s. That’s one of the reasons I’m a big Linux user: when something goes wrong, it’s my fault, not my system’s. Therefore, I know what went wrong and it’s fully in my control as opposed to being a problem out of my hands and in the power of another developer. In fact, I cannot recall Linux ever failing me in my 6 or so years of being a daily driver user.

I have to dabble in Android app development for one of my classes, and Android Studio is one of the worst pieces of software I’ve ever used, ever. I tried learning it. I tried putting up with it. Simply put, I cannot bear it. One of the things about me is that my system is essentially kinda like an IDE that I assembled myself. I’m running Arch Linux (I use Arch btw) with a custom rice setup I made including i3-gaps, Polybar, dmenu, st, and a bunch of scripts, macros, keybinds, and more that I made specifically for my system. Using Android Studio, by comparison, is like what happens when you get a professional skateboarder a $20 Wal-Mart board. It’s painful to use.

Luckily, I don’t have to use an IDE. It’s totally possible to develop Android apps using vim and a terminal!

Packages

We need a couple of packages in order to get the tools that we need for developing on a terminal. Luckily for us, we don’t have to go to strange and obscure websites riddled with ads and malware on the Internet to get our programs – that’s what Windows users do. Instead, we can just install what we need using our system’s package manager.

We need android-sdk-cmdline-tools-latest, which is available in the AUR, and android-tools, which is available in the Arch repos:

$ yay -Sy android-sdk-cmdline-tools-latest
$ sudo pacman -Sy android-tools

You should reboot or login again after installing.

Android SDK

We need some basic packages from the Android SDK now. I’ll go ahead and make and define the directory environment variable in my ~/.bashrc. I’m using ~/.android-sdk/, but you can really make it wherever you’d like:

$ mkdir ~/.android-sdk/

~/.bashrc

export ANDROID_HOME="/home/skat/.android-sdk/"
export ANDROID_SDK_ROOT="/home/skat/.android-sdk/"

Then I’ll just install the items I need using sdkmanager. I’m installing the stuff I need for Android API 29, but you should replace it with whatever you need depending on what API you’re developing with:

$ sudo sdkmanager --install "platform-tools" "build-tools;29.0.0" "platforms;android-29"

This installs to /opt/android-sdk/. I’ll go ahead and copy it to my ~/.android-sdk/ directory:

$ cp -r /opt/android-sdk/* ~/.android-sdk/

Now we’re done!

Workflow

At this point, you can use whatever text editor you want to write your source code. I personally use vim, but to each their own.

When you’re ready, you’ll need to compile your projects into APKs with gradlew. These are typically not executable by default, so you’ll have to add executability before running it to assemble a debug version of your app:

$ chmod +x ./gradlew
$ ./gradlew assembleDebug

Depending on your project, the APK may appear in different places in your directory structure. For example, app/buid/outputs/apk/debug/app-debug.apk is where the output APK appears on my current project. We can upload this to an actual Android device by connecting via a USB cable, enabling debug mode on the phone, and then installing from our computer with adb, after which the app will appear on the phone:

$ adb -d install app/build/outputs/apk/debug/app-debug.apk

Alternatively, you can do the same in with gradlew:

$ ./gradlew installDebug

Hey, look at that: you can now develop Android apps using whatever workflow you want thanks to the power of the terminal.

Happy hacking!