r/JetpackComposeDev • u/Realistic-Cup-7954 • Sep 15 '25
Tips & Tricks API Keys in Android: How do you keep them safe?
API keys are critical to any app, but they are also one of the easiest things to leak if not handled properly. A few things to check:
Donโt hardcode keys in the codebase
Use Gradle properties or BuildConfig
Move sensitive keys to a backend and use tokens
Obfuscate code with ProGuard/R8
Store keys in the Android Keystore
Rotate keys regularly and monitor usage
Credit : Gayathri & Pradeep
5
u/Anonymous0435643242 Sep 15 '25
You don't, you store your API keys on the backend and provide access through authentication.
3
3
1
u/Few-Grape-4445 Sep 15 '25
Thanks, this is very important to keep into account
Which would be the method to keep secure a Google Maps API key?
By now I have restricted the access of it from the GCP console to be used only for my app and I excluded it from VCS, I think it should be enough












2
u/Realistic-Cup-7954 Sep 15 '25
EncryptedSharedPreferencesis deprecatedWe can use the Android Keystore system + platform crypto APIs (AES/GCM) directly instead.
Official docs: Android Cryptography