Today’s #AndroidDev #Protip from +Ankur Kotwal is about using Gradle build types.
Gradle  enables you to declare multiple build types, allowing you to vary signing keys, package names, source sets, resources, and configuration files. These can be used to separate out development builds from usertest and release builds.
To get started, declare signing configurations for the build types. Signing configurations allow you to specify the keystore and alias to sign the APK with. You can reuse the same signing config for multiple build types but its best to have a dedicated one for release. It’s generally not a good idea to store your release configuration in plain text and thus a release signing config has not been specified here - this will result in an unsigned APK. signingConfigs
Next, you need to declare the build types. Here we can see that the debug and usertest builds are using different suffixes for package names and for the app version. Having unique package names enables all three build type APKs to be installed on the device at once - this is a big time saver during development. Release builds should always use ProGuard to obfuscate the APK and remove unused code. It’s a good idea to turn ProGuard on for usertest builds too since the aim is for these builds to resemble the release build as much as possible. buildTypes
A Gradle project’s directory structure helps to differentiate individual files between each build type. Gradle will overlay the “main” directory with the files in the active build type at build time. This enables you to provide custom configuration files enabling you to point your debug, usertest and release APKs to point to their respective sandbox, staging and production backends. Since we’re using different package names and potentially installing multiple versions of the app on different devices, you might want to use a different app icon for each build type.
Gradle can help you create a very powerful build setup with relative ease. Gradle integration is available in Android Studio / IntelliJ .