local.properties의 값 가져오기

Beaver Bridge - Apr 25 - - Dev Community

kts 기준

local.properties

API_KEY="akldfjjasdfualksjdfalsdhfulaskjhd"
Enter fullscreen mode Exit fullscreen mode

app/build.gradle.kts

import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

android {
  defaultConfig {
    buildConfigField("String", "API_KEY", readProperty("API_KEY"))
  }
}

fun readProperty(key: String): String =  gradleLocalProperties(rootDir, providers).getProperty(key)
Enter fullscreen mode Exit fullscreen mode

사용법

BuildConfig.API_KEY
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . .