Android Gradle command line list examples

This tutorial talks about gradle commands used in Android applications.

You can do the same tasks using Android Studio.

Knowing commands is helpful for mobile developers to gain confidence in app build and deployment.

How to list tasks from the command line in the Android application

The Gradle wrapper provides a task command to list out all available tasks in the Android app.

In Windows, Please run the following command

gradlew tasks

In Linux or Mac or Unix flavors OS machines.

gradlew tasks

How to build an APK file in an Android project?

Sometimes, We need to generate APK for debugging and testing the app assembleDebug: Following is a command for generating debug APK files with default signed configuration.

gradlew assembleDebug

The output of the above command generates module-debug.apk in project/module/build/outputs/apk/ folder Another way is with offline mode.

./gradlew assembleDebug --offline

Generate apk files without downloading network dependencies. assembleRelease:

It builds and generates a release version of the APK file.

gradlew assembleRelease

It generates module-release.apk in project/module/build/outputs/apk/ folder assemble:

It generates debug and release versions of apk for debugging and release with default signing configuration.

gradlew assemble

It generates module-release.apk and module-debug.apk in project/module/build/outputs/apk/ folder

How to install apk files to Android devices?

install variants build and generate apk file and install apk to available devices

gradlew installDebug // build & installs debug apk
gradlew install // build & installs release apk

How to deploy the Android app to the emulator

  • First, create Android virtual devices.
  • Command-line run below command to start the emulator
android_sdk/tools/emulator -avd nameofavd

The next step is to deploy to the emulator with the ADB command

adb install  apkfilepath

apkfilepath is an apk file generated with the gradle assemble or gradle install command.

Normally, apk generates in the project/module/build/outputs/apk/ folder by default.

How to build an application bundle with Gradle?

Android application bundle contains compiled Java code and required resources.

Here is a command to generate bundled code

gradlew :base:bundleDebug

Sync gradle scripts manually in Android studio

use the below command to syn without build

Below gradle version 5.1.1

gradle --recompile-scripts

With recent release

gradle prepareKotlinBuildScriptModel

To run build and sync manually

./gradlew build

How to check Dependencies for Updates in Android gradle

./gradlew dependencyUpdates

It checks the dependencies for updated versions and updates to it.

Check Gradle dependencies tries in a project

It displays the dependencies tree for an application.

./gradlew app:dependencies

Other commands

For checking lint on the android project

./gradlew lint

For running unit tests of an Android project.

./gradlew test

Check build process information using --scan option

./gradlew --scan

For signing preoprt of a project.

./gradlew signingReport

Printing properties information using the below command

./gradlew properties