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.
commandlinetools-linux-6609375_latest.zip gradle-6.5.1-all.zip
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
java.lang.IllegalArgumentException
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
/media/data/android_sdk/cmdline-tools/tools/bin/sdkmanager
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
setpath_android()
{
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