Keystore Decryption & Pre-Flight Guards
Never commit unencrypted .keystore, .jks, or plaintext signing passwords to Git. Storing them in CI variables as base64 strings is prone to truncation and escaping errors when managing multiple brand keys.
A recommended pattern is bundling all keystores and .properties into an AES-256 encrypted tarball committed directly to the repository, decrypted on-demand in CI memory/temp storage.
1. Creating the Encrypted Signing Bundle
Locally on your machine:
# Package all brand keystores and signing propertiestar -czf android/signing_bundle.tar.gz -C android/signing .
# Encrypt with OpenSSL using AES-256-CBCopenssl enc -aes-256-cbc -pbkdf2 -salt \ -in android/signing_bundle.tar.gz \ -out android/signing_bundle.enc \ -k "$SIGNING_PASSPHRASE"
# Remove the plaintext tarballrm android/signing_bundle.tar.gzCommit android/signing_bundle.enc to Git. Store only $SIGNING_PASSPHRASE in your CI environment secrets.
2. Automated Decryption in Fastlane
In your Android Fastfile or custom action, add an unpacking helper that runs prior to any build:
def unpack_signing(passphrase:) enc_file = File.expand_path('../../android/signing_bundle.enc', __dir__) target_dir = File.expand_path('../../android/signing', __dir__)
UI.user_error!("Signing bundle #{enc_file} not found!") unless File.exist?(enc_file) UI.user_error!("SIGNING_PASSPHRASE is not set!") if passphrase.nil? || passphrase.empty?
FileUtils.mkdir_p(target_dir)
# Decrypt and extract in a single piped pipeline sh("openssl", "enc", "-d", "-aes-256-cbc", "-pbkdf2", "-in", enc_file, "-k", passphrase, "|", "tar", "-xzf", "-", "-C", target_dir)
UI.success("Successfully decrypted signing bundle into #{target_dir}")end3. Pre-Flight Environment Guard
To prevent builds from failing 20 minutes in due to a missing environment variable, enforce a pre-flight guard at the very beginning of execution:
module EnvironmentVerifierHelper REQUIRED_VARS = %w[ PLAY_STORE_JSON_KEY_PATH SIGNING_PASSPHRASE ].freeze
def self.verify! missing = REQUIRED_VARS.select { |var| ENV[var].nil? || ENV[var].strip.empty? }
return if missing.empty?
UI.user_error!( "❌ Pre-Flight Guard Failed! Missing required environment variables:\n" \ " - #{missing.join("\n - ")}\n\n" \ "Please define them in your .env file or CI secrets configuration." ) endendCall this in before_all or at the top of your root Fastfile:
require_relative 'helpers/environment_verifier_helper'EnvironmentVerifierHelper.verify!