Building Android App without IDE from the command line

Recently I got the source code of one particular Android App from github and I wanted to build that on my Debian Unstable latest.  I was just trying to see how I could build without installing the IDE.  This is what I did.
apt-get install default-jdk

From Android site I downloaded both commandlinetools and gradle. Got the following versions downloaded.
I chose to install it in the larger partition which is mounted as /media/data so I created a new directory /media/data/android_sdk
Then unzipped the above two zip files there.

There was a java error while using the sdkmanager.

Warning: Could not create settings

After searching a bit, I found a solution for that. We need to create a directory “cmdline-tools”. So I created it and moved the tools directory there. Effectively, the sdkmanager could be located at
Now we need to make sure that the sdkmanager and gradle are in the PATH. I only wanted to include them during App building. So, wrote a simple function and placed it in ${HOME}/.bashrc

export PATH=/media/data/android_sdk/cmdline-tools/tools/bin:/media/data/android_sdk/gradle-6.5.1/bin
export ANDROID_SDK_ROOT=/media/data/android_sdk
echo ${PATH}

Just run “setpath_android” from the Bash whenever we want to build.
Now, we have to install the platform-tools, build-tools and related packages. As my phone is Android Oreo 8.1.0, I wanted to install API Level 27.

sdkmanager --version
sdkmanager --update
sdkmanager --licenses
sdkmanager --list
sdkmanager --install "platforms;android-27"
sdkmanager --install "build-tools;27.0.3"
sdkmanager --install "extras;android;m2repository" "extras;google;m2repository"
sdkmanager --install "cmdline-tools;latest"

Now, goto the directory of the Application which was cloned from github. Let us say it is myapp

cd /path/to/myapp
gradle build -x test

With this much, I could build the application without having the IDE and completely from the command line

Published by Anand Sivaram (आनन्दः )

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: