Lawrence Gimenez

Compiling Android on the Command Line

First of all, I am on Manjaro Xfce environment for this example.

We need to install Gradle. I tried to install Gradle using ArchLinux’s pacman but it was very outdated. So based on Gradle’s installation guide one option is to use a package manager like Sdkman.

Let’s go ahead and install SDKMAN!.

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

After running SDKMAN!, close the current terminal and open a new one. Then run

sdk install gradle

But when I try to run gradle or java, it will throw an error No Java found.

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

We need to install Java’s JDK.

sudo pacman -S jre-openjdk-headless jre-openjdk jdk-openjdk openjdk-doc openjdk-src

At this point, running java should now work.

java --version
openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment (build 18.0.2+9)
OpenJDK 64-Bit Server VM (build 18.0.2+9, mixed mode)

And running gradle should also work likewise.

gradle -v
Welcome to Gradle 7.5!

Here are the highlights of this release:
 - Support for Java 18
 - Support for building with Groovy 4
 - Much more responsive continuous builds
 - Improved diagnostics for dependency resolution

For more details see https://docs.gradle.org/7.5/release-notes.html


------------------------------------------------------------
Gradle 7.5
------------------------------------------------------------

Build time:   2022-07-14 12:48:15 UTC
Revision:     c7db7b958189ad2b0c1472b6fe663e6d654a5103

Kotlin:       1.6.21
Groovy:       3.0.10
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          18.0.2 (Oracle Corporation 18.0.2+9)
OS:           Linux 5.15.57-2-MANJARO amd64

When you cd to your Android project, gradle should work.

gradle build