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 get 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
Output of the above command generates module-debug.apk
in project/module/build/outputs/apk/
folder
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
- 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 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 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