Setting up different builds for android
A year ago google released android studio.An IDE based on intellij.They also introduced a task runner to build your applications, run test and manage dependencies.
Gradle is the task runner and it supports a Java,Android and C/C++ projects.That what they claim on their website.But for this post I will be dealing with android.
The android gradle project has buildTypes which are equivalent to environments in the backend development world.Android has 2 by default one is debug the other is release.You can specify more buildtypes based on your application.
You can easily create another buildtype
signingConfigs { prerelease { storeFile file("prerelease.keystore") storePassword "<your password>" keyAlias "<key.alias>" keyPassword "<your password>" } } buildTypes { prerelease { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.prerelease } }
You need to add the signingConfig this way it will build and sign the keys before installing.
By default the Install
Here are the other options available to each buildtype
If a property is not set through the DSL, some default value will be used. Here’s a table of how this is processed.
Property Name | Default value in DSL object | Default value |
**versionCode** | -1 | value from manifest if present |
**versionName** | null | value from manifest if present |
**minSdkVersion** | -1 | value from manifest if present |
**targetSdkVersion** | -1 | value from manifest if present |
**applicationId** | null | value from manifest if present |
**testApplicationId** | null | applicationId + “.test” |
**testInstrumentationRunner** | null | android.test.InstrumentationTestRunner |
**signingConfig** | null | null |
**proguardFile** | N/A (set only) | N/A (set only) |
**proguardFiles** | N/A (set only) | N/A (set only) |
Source: Google
By default gradle looks for the keystore file in the app/ directory.
You can also run multiple gradle jobs in parallel, by setting the following in the gradle.properties file.
org.gradle.parallel=true
Using buildtype can improve overall code quality especially if you have multiple config data like server urls.
To override a particular file for a particular build all you have to is create a folder in the src/ directory.