Sign APK without putting keystore info in build.gradle
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Android development, signing an APK is a crucial process that ensures the authenticity and integrity of an application. Typically, the signing configuration, including the keystore information, is specified within the build.gradle
file. However, exposing keystore information in source control can lead to significant security risks. This article explores how to sign an APK without embedding keystore details directly in the build.gradle
file, offering technical explanations and examples.
Why Avoid Keystore Info in build.gradle?
Storing sensitive keystore details in build.gradle
files can expose your application's credentials if the source code is publicly accessible or if the source code is shared with multiple team members. By keeping this information secure, you can guard against unauthorized access and potential security vulnerabilities.
Alternatives to Storing Keystore Info in build.gradle
To protect sensitive information, developers can opt for the following approaches:
- Local Properties File: Store the signing configuration in a separate
key.propertiesfile which is not checked into version control. - Environment Variables: Utilize system environment variables to pass keystore information during the build process.
- CI/CD Secrets Management: Configure continuous integration and deployment (CI/CD) pipelines to inject secret data during builds.
1. Using a Local Properties File
This method separates the keystore information from the source code. Here’s how to implement it:
- Step 1: Create a
key.propertiesfile at the root of your project directory. - Step 2: Modify the
build.gradlefile to read from this properties file. - Step 3: Ensure
key.propertiesis added to your.gitignoreto prevent it from being included in version control. - Set Environment Variables:
- Modify build.gradle:
- Inject Secrets During Build: Most CI/CD systems (e.g., GitHub Actions, Jenkins) allow for secure environment variables that can be incorporated into the build process.
- Reference in build.gradle is similar to using environment variables.
Related reading
- Sign in with Apple Java User Verification
- SignalR 2.0 error Could not load file or assembly Microsoft.Owin.Security
- Signature expired is now earlier than error InvalidSignatureException
- Signing ElasticSearch AWS calls
- Simple embedded Kafka test example with spring boot
- Simple HTTP server in Java using only Java SE API
- Silent Push Notification in iOS 7 does not work
- Silent pushes not delivered to the app on iOS 11

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.