안드로이드 Kotlin-DSL local.properties 사용
안드로이드에서 local.properties를 사용해서 API 키나 숨겨야 하는 것이 있을 때 일반적으로 Groovy 사용할 때는
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
android {
...
defaultConfig {
...
buildConfigField "String", "APIKEY", properties["apiKey"]
}
}
위와 같이 사용하면 되지만
Kotlin-DSL를 사용하는 경우라면 위와 같은 방법으론 해결할 수 없고
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
android {
...
defaultConfig {
...
buildConfigField("String", "APIKEY", gradleLocalProperties(rootDir).getProperty("apiKey"))
}
}
이런 식으로 처리해야 한다