We may want to keep our Android project keystore details out of our source code and Git by passing them in. Aided by a handy function in buildSrc, these can be referenced from Gradle in Groovy or Kotlin. 🚀

import org.gradle.api.Project

fun Project.propertyOrEmpty(name: String): String {
    return findProperty(name) as String? ?: ""
}

android {
  signingConfigs {
    create("upload") {
      storeFile = file("upload.keystore")
      storePassword = propertyOrEmpty("UPLOAD_STORE_PASSWORD")
      keyAlias = "keyname"
      keyPassword = propertyOrEmpty("UPLOAD_KEY_PASSWORD")
    }
  }
}

Thanks for reading and happy coding! 🙏