Gradle & Code Quality

Secrets Gradle Plugin: Avoid Git Leaks Without Claiming APK Secrecy

The Secrets Gradle Plugin helps keep configuration values out of source control. It does not make an API key secret after that key is compiled into an APK. Build-time injection and runtime confidentiality are different problems.

By Updated 2 min read

Use the plugin for the right purpose

The official plugin guidance describes reading local configuration and exposing values to the Android build. This can reduce accidental Git commits and make environment-specific setup clearer.

A key included in a manifest, resource or generated constant can still be extracted from the distributed application. Do not put privileged backend credentials into the client simply because they came from an ignored properties file.

Separate configuration classes

Value Handling direction
Client API key designed for an app Apply provider-supported app/API restrictions
Local development endpoint Keep environment-specific and out of release where unnecessary
Backend administrative secret Keep on the server or approved build infrastructure
Signing password or upload token Use protected build secrets, never package into the app

Avoid naming every configuration value “secret”; the actual authority it grants determines the risk.

Make missing values fail clearly

Provide safe development defaults only where they cannot accidentally point a release at the wrong service. For required release configuration, fail the build with a clear message rather than silently inserting an empty key or a test project identifier.

Do not print full values in Gradle logs when diagnosing a missing property.

Restrict and test client keys

Use the provider's supported restrictions, such as package/signing identity and allowed APIs where applicable. Test the actual Play-signed release identity, not only the local debug certificate. A valid key with the wrong restrictions can work in one distribution channel and fail in another.

Inspect the final package

APKLint can help identify key-like values and manifest configuration. Its scanner cannot establish whether a provider's server-side restrictions are correct. Follow Android security guidance, review the cloud-side configuration and treat a leaked privileged credential as a rotation incident, not merely a string to remove from the next APK.

Sources and further reading

  1. Google Maps Platform: Secrets Gradle plugin
  2. Android Developers: Security best practices

Reference review: 22 September 2026. Examples illustrate the workflow; check your installed versions, release artifact and account-specific Console requirements before applying them. This guide is not a claim that APKLint executed your project or verified your private account.

APKLint

Android inspection tools and practical release guides. About APKLint · Report a correction