Android Studio ; How to  Reduce Gradle Build Time

Android Studio ; How to Reduce Gradle Build Time

Improve your productivity by reducing gradle build time

·

2 min read

Sometimes android studio can take 30 minutes or even an hour to successfully build an app bundle or an APK. I use these “hacks” to greatly reduce build time and effectively improve my productivity when building android apps using android studio.

First Instead of building an android app by pressing Run from Android studio I use the terminal. To build and install a debug app I use;

./gradlew installDebug

This command will build and install the debug version of the app on the emulator or to your connected android device with USB debugging and already connected to the computer.

To build a release version you will be required to add additional configurations to the app level build.gradle; generate app signing key in the app folder, define keystore password,alias, and name in the gradle.properties file.

gradle.properties

RELEASE_STORE_FILE=keystore_name
RELEASE_STORE_PASSWORD=password
RELEASE_KEY_ALIAS=alias
RELEASE_KEY_PASSWORD=password

build.gradle

  signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

With this configuration you can now build a release version of the apk or app bundle by running the following commands.

To generate release apk

./gradlew installRelease

To generate app bundle

./gradlew bundleRelease

These commands will generate a signed app bundle or apk. Without setting up the signing configs in the build.gradle we would get an error bundleRelease candidate not available.

Happy Coding