Skip to content

Instantly share code, notes, and snippets.

@Ehsanul-Hoque
Last active April 5, 2020 13:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Ehsanul-Hoque/f80e5b4f270db3de3a86efb7e38a3c13 to your computer and use it in GitHub Desktop.
app level build.gradle file for app automation
// ...
android {
// ...
signingConfigs {
release
}
// To let gradle automate signing process, lintOptions to be added
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "${APPLICATION_ID}" // APPLICATION_ID field in the gradle.properties file
// ...
// Defining the app name
// (Both as build config constant and string resource value)
buildConfigField "String", "APP_NAME", "\"$APP_NAME\""
resValue "string", "app_name", APP_NAME
// Defining the colors
// (Only as color resource value. We don't need create build config constant)
resValue "color", "colorPrimary", THEME_COLOR
resValue "color", "colorPrimaryDark", THEME_COLOR
}
buildTypes {
release {
// ...
}
}
// ...
}
// ...
// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, relative to the rootProject folder.
def keystorePropertiesFile = rootProject.file(KEYSTORE_INFO_FILE) // KEYSTORE_INFO_FILE field in the gradle.properties file
// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists() && keystorePropertiesFile.canRead()) {
// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
if ((keystoreProperties != null) && keystoreProperties.containsKey('STORE_FILE')
&& keystoreProperties.containsKey('KEY_STORE_PASSWORD')
&& keystoreProperties.containsKey('KEY_ALIAS')
&& keystoreProperties.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = rootProject.file(keystoreProperties['STORE_FILE'])
android.signingConfigs.release.storePassword = keystoreProperties['KEY_STORE_PASSWORD']
android.signingConfigs.release.keyAlias = keystoreProperties['KEY_ALIAS']
android.signingConfigs.release.keyPassword = keystoreProperties['KEY_PASSWORD']
println 'signing.properties found'
android.buildTypes.release.signingConfig = android.signingConfigs.release
} else {
println 'signing.properties found but some entries are missing'
android.buildTypes.release.signingConfig = null
}
} else {
println 'signing.properties not found'
android.buildTypes.release.signingConfig = null
}
// I've taken help from this awesome blog to modify the build.gradle file:
// https://medium.com/mindorks/how-did-i-automate-the-generation-of-release-apk-3e42b6540a4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment