Hiding API keys in local.properties Add the API key to your local.properties file: apiKey=<value> serverKey=<value> mapKey=<value> Add to the root level of your app-level build.gradle file: def localProperties = new Properties() localProperties.load(new FileInputStream(rootProject.file("local.properties"))) Add to the android { defaultConfig { } } block of your app-level build.gradle file: android { // ... defaultConfig { // ... buildConfigField "String", "API_KEY", localProperties['apiKey'] buildConfigField "String", "SERVER_KEY", localProperties['serverKey'] buildConfigField "String", "MAP_KEY", localProperties['mapKey'] } // ... } Sync Gradle and build the project. You can now reference the key: val apiKey = BuildConfig.API_KEY val serverKey = BuildConfig.SERVER_KEY val mapKey = BuildConfig.MAP_KEY String apiKey = BuildConfig.API_KEY String serverKey = BuildConfig.SERVER_KEY String mapKey = BuildConfig.MAP_KEY
Please update this file for Kotlin too