Last active
April 5, 2020 13:08
Star
You must be signed in to star a gist
app level build.gradle file for app automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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