Skip to content

Instantly share code, notes, and snippets.

@sDevPrem
Created May 27, 2024 08:21
Show Gist options
  • Save sDevPrem/54d3ba4e910c70169ae63a61fd0321b1 to your computer and use it in GitHub Desktop.
Save sDevPrem/54d3ba4e910c70169ae63a61fd0321b1 to your computer and use it in GitHub Desktop.
/local.properties
object APIConstant {
const val BASE_URL = "https://example.com/"
//After gradle sync and Rebuilding the project, BuildConfig File will
//gerated with constants
const val API_KEY = BuildConfig.API_KEY
}
//in app module gradle file
import java.util.Properties
val localProperties = Properties()
val localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.inputStream().use { input ->
localProperties.load(input)
}
}
android {
defaultConfig {
buildConfigField(
type = "String",
name = "API_KEY",
value = localProperties["API_KEY"].toString()
)
}
buildFeatures {
buildConfig = true
}
}
API_KEY="my_api_key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment