2026/03/06

오늘의 이야기

https://barros9.medium.com/how-to-keep-your-certificates-and-api-keys-secrets-on-android-ebc5fde4b106



 


How to keep your certificates and API Keys secrets on Android 🤫


It could happen that pre-lunch report of your app reports a security issue: Your app contains exposed Google Cloud Platform (GCP) API keys


barros9.medium.com




원작자의 글 : 위 링크에 있는 원작자의 말은 공개된 소스 창고(git 등)에 소스를 게시하는 경우 극히 개인적이어야 하는 API Key등을 숨기는 방법에 대해서 이야기를 하고 있다.  나야 뭐 git 등에 게시할 만큼의 skill 이 없으니 다행(?)이라고 생각이 들기는 한다. 


 


아무튼 local.properties 의 활용에 대해서 공부를 해 보는 기회가 되기를 바래 본다.  


 


1. API key 등은 local.properties 에 저장하자.


dev.googleApiKey="????????????????????????????????????????"
prod.googleApiKey="????????????????????????????????????????"

2. 다음은 build.gradle 파일에 저 값을 가져 오도록 설정해 두어야 한다.


def localPropertiesFile = rootProject.file('local.properties')
def localProperties = new Properties()
localProperties.load(new FileInputStream(localPropertiesFile))

3. 다음은 gradle 파일에서 그 값을 활용할 수 있도록 선언해 주는 것이다. 


buildTypes {
debug {
resValue "string", "GOOGLE_API_KEY", "${localProperties.getProperty("dev.googleApiKey")}"
}
release {
resValue "string", "GOOGLE_API_KEY", "${localProperties.getProperty("prod.googleApiKey")}"
}
}

4. 그리고 이제 소스에서 읽어 올때는 다음과 같이 하면 된다.


getString(R.string.GOOGLE_API_KEY)

 


끝.


 


그런데 firebase 을 활용하는 동안에는 google-service.json 이라고 저런 API key가 들어있는 파일을 내려받아, apps 폴더에 넣고 개발을 하는데, 이 때는 어떻게 하라는 말인가 ?


 


흠... 이것도 찾아 보아야 겠다.


 


 


locale.properties



 





댓글 없음:

댓글 쓰기

오늘의 이야기

#스치니1000프로젝트 #재미 #행운기원 #Compose #Firebase 🎯 야 너 토요일마다 로또 확인하냐? 나도 맨날 “혹시나~” 하면서 봤거든 ㅋㅋ 근데 이제는 그냥 안 해 AI한테 맡겼어 🤖✨ 그것도 구글 Gemini로다가! ...