Build and Debug Your Android From the Command Line

Build and Debug Your Android from the Command Line.
Use gradle/gradlew.
These commands all execute under android gradle project’s root folder.

1. show all useable gradlew commands:

1
./gradlew tasks

2. Build a debug APK

1
./gradlew assembleDebug

3. Build the APK and immediately install it on a running emulator or connected device:

1
./gradlew installDebug

4. Build a release version.

1
./gradlew assembleRelease
  • You must config your singningConfigs to enable release build. If you had not config this, this command will build a unsigned apk.

Open the module-level build.gradle file and add the signingConfigs {} block with entries for storeFile, storePassword, keyAlias and keyPassword, and then pass that object to the signingConfig property in your build type. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file("my-release-key.jks")
storePassword "password"
keyAlias "my-alias"
keyPassword "password"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
...
}
}
}

  • Because Gradle reads paths relative to the build.gradle, the above example works only if my-release-key.jks is in the same directory as the build.gradle file.