Created
May 27, 2024 08:21
-
-
Save sDevPrem/54d3ba4e910c70169ae63a61fd0321b1 to your computer and use it in GitHub Desktop.
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
/local.properties |
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
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 | |
} |
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
//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 | |
} | |
} |
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
API_KEY="my_api_key" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment