CI/CD pipelines for Android with GitHub Actions, Gradle, and Play Console deployment.
GitHub Actions Setup
# .github/workflows/android.yml
name: Android CI/CD
on:
push:
branches: [main, develop]
tags: ['v*']
pull_request:
branches: [main, develop]
env:
JAVA_VERSION: '21'
GRADLE_VERSION: '8.5'
jobs:
# Lint and format check
lint:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Run lint
run: ./gradlew lint
- name: Check formatting (ktlint)
run: ./gradlew ktlintCheck
- name: Upload lint report
if: always()
uses: actions/upload-artifact@v4
with:
name: lint-report
path: app/build/reports/lint-results.html
# Unit tests
unit-test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Run unit tests
run: ./gradlew test
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: unit-test-reports
path: app/build/reports/tests/
# Instrumented tests (requires emulator)
instrumented-test:
name: Instrumented Tests
runs-on: macos-latest # macOS for better emulator performance
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- name: Start emulator
uses: android-actions/emulator@v2
with:
api-level: 34
arch: arm64
force-avd-creation: true
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -no-boot-anim
- name: Wait for emulator
run: |
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done'
- name: Run instrumented tests
run: ./gradlew connectedAndroidTest
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: instrumented-test-reports
path: app/build/reports/androidTests/
# Build APK/AAB
build:
name: Build
runs-on: ubuntu-latest
needs: [lint, unit-test]
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Decode signing key
if: github.event_name != 'pull_request'
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
echo "$KEYSTORE_BASE64" | base64 -d > app/release.keystore
echo "storeFile=../release.keystore" >> local.properties
echo "storePassword=$KEYSTORE_PASSWORD" >> local.properties
echo "keyAlias=$KEY_ALIAS" >> local.properties
echo "keyPassword=$KEY_PASSWORD" >> local.properties
- name: Build Debug APK
run: ./gradlew assembleDebug
- name: Build Release AAB
if: github.event_name != 'pull_request'
run: ./gradlew bundleRelease
- name: Upload Debug APK
uses: actions/upload-artifact@v4
with:
name: debug-apk
path: app/build/outputs/apk/debug/app-debug.apk
- name: Upload Release AAB
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: release-aab
path: app/build/outputs/bundle/release/app-release.aab
# Deploy to Play Console (Internal Testing)
deploy-internal:
name: Deploy to Internal Testing
runs-on: ubuntu-latest
needs: [build, instrumented-test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Download AAB
uses: actions/download-artifact@v4
with:
name: release-aab
path: app/build/outputs/bundle/release/
- name: Deploy to Play Console
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.PLAY_SERVICE_ACCOUNT }}
packageName: com.example.myapp
releaseFiles: app/build/outputs/bundle/release/app-release.aab
track: internal
status: draft
inAppUpdatePriority: 2
# Deploy to Play Console (Production)
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/v')
environment: production
steps:
- uses: actions/checkout@v4
- name: Download AAB
uses: actions/download-artifact@v4
with:
name: release-aab
path: app/build/outputs/bundle/release/
- name: Deploy to Play Console
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.PLAY_SERVICE_ACCOUNT }}
packageName: com.example.myapp
releaseFiles: app/build/outputs/bundle/release/app-release.aab
track: production
status: completed
rollout: 0.1 # 10% rollout
userFraction: 0.1Gradle Configuration for CI
// build.gradle.kts (app)
android {
// CI-friendly configuration
buildTypes {
release {
// Disable CRUNCH for CI speed
crunchPngs = false
}
}
// Test options for CI
testOptions {
unitTests {
isIncludeAndroidResources = true
returnDefaultValues = true
all {
useJUnitPlatform()
testLogging {
events = setOf("passed", "skipped", "failed")
}
}
}
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
// Build cache for CI
buildCache {
isLocalEnabled = true
}
}
// Dependencies for CI
dependencies {
// Test orchestrator
androidTestUtil("androidx.test:orchestrator:1.4.2")
// Test runner
androidTestImplementation("androidx.test:runner:1.5.2")
androidTestImplementation("androidx.test:rules:1.5.0")
}Keystore Setup
# Generate keystore
keytool -genkeypair -v \
-keystore release.keystore \
-alias my-key \
-keyalg RSA \
-keysize 2048 \
-validity 10000 \
-storepass <password> \
-keypass <password> \
-dname "CN=My Company, OU=Android, O=My Company, L=City, S=State, C=US"
# Export to base64 for GitHub Secrets
base64 -i release.keystore -o release.keystore.base64
# Add to GitHub Secrets:
# KEYSTORE_BASE64 (content of base64 file)
# KEYSTORE_PASSWORD
# KEY_ALIAS (my-key)
# KEY_PASSWORD// build.gradle.kts - Signing config
android {
signingConfigs {
create("release") {
val storeFile = project.rootProject.file("app/release.keystore")
storeFile = storeFile
storePassword = project.findProperty("KEYSTORE_PASSWORD")?.toString() ?: ""
keyAlias = project.findProperty("KEY_ALIAS")?.toString() ?: ""
keyPassword = project.findProperty("KEY_PASSWORD")?.toString() ?: ""
}
create("debug") {
storeFile = file("../debug.keystore")
storePassword = "android"
keyAlias = "androiddebugkey"
keyPassword = "android"
}
}
buildTypes {
release {
signingConfig = signingConfigs.getByName("release")
}
debug {
signingConfig = signingConfigs.getByName("debug")
}
}
}Play Console Service Account
# 1. Go to Google Play Console → Setup → API Access
# 2. Create service account
# 3. Grant permissions:
# - Release Manager
# - View App Information
# 4. Download JSON key
# 5. Add to GitHub Secrets as PLAY_SERVICE_ACCOUNT
# JSON format:
{
"type": "service_account",
"project_id": "my-project",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "release-manager@my-project.iam.gserviceaccount.com",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/..."
}Fastlane Alternative
# Gemfile
source "https://rubygems.org"
gem "fastlane"
# fastlane/Fastfile
default_platform(:android)
platform :android do
desc "Build and deploy to internal testing"
lane :internal do
gradle(
task: "clean bundleRelease",
project_dir: "app/"
)
upload_to_play_store(
track: "internal",
aab: "app/build/outputs/bundle/release/app-release.aab",
json_key: "fastlane/play-console-key.json",
package_name: "com.example.myapp",
skip_upload_apk: true,
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true
)
end
desc "Build and deploy to production with rollout"
lane :production do
gradle(
task: "clean bundleRelease",
project_dir: "app/"
)
upload_to_play_store(
track: "production",
aab: "app/build/outputs/bundle/release/app-release.aab",
json_key: "fastlane/play-console-key.json",
package_name: "com.example.myapp",
rollout: "0.1"
)
end
desc "Promote internal to production"
lane :promote do
upload_to_play_store(
track: "internal",
track_promote_to: "production",
json_key: "fastlane/play-console-key.json",
package_name: "com.example.myapp"
)
end
end
# Run locally
# bundle exec fastlane android internal
# bundle exec fastlane android productionGitHub Actions with Fastlane
# .github/workflows/fastlane.yml
name: Fastlane Deploy
on:
workflow_dispatch:
inputs:
track:
description: 'Track to deploy'
required: true
default: 'internal'
type: choice
options: [internal, alpha, beta, production]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Decode keystore
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
run: echo "$KEYSTORE_BASE64" | base64 -d > app/release.keystore
- name: Decode Play Console key
env:
PLAY_KEY_BASE64: ${{ secrets.PLAY_KEY_BASE64 }}
run: echo "$PLAY_KEY_BASE64" | base64 -d > fastlane/play-console-key.json
- name: Run Fastlane
run: bundle exec fastlane android ${{ github.event.inputs.track }}
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}Version Bumping
# .github/workflows/version-bump.yml
name: Version Bump
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version type'
required: true
type: choice
options: [patch, minor, major]
jobs:
bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version
id: version
run: |
# Read current version from gradle.properties
CURRENT=$(grep "versionName" gradle.properties | cut -d'=' -f2)
# Bump based on input
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "${{ github.event.inputs.version_type }}" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
# Update gradle.properties
sed -i "s/versionName=.*/versionName=$NEW_VERSION/" gradle.properties
sed -i "s/versionCode=.*/versionCode=$((MAJOR * 10000 + MINOR * 100 + PATCH))/" gradle.properties
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Commit and tag
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add gradle.properties
git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}"
git tag "v${{ steps.version.outputs.new_version }}"
git push origin main --tagsMonitoring & Notifications
# Slack notification
- name: Notify Slack on failure
if: failure()
uses: 8398a7/action-slack@v3
with:
status: failure
channel: '#android-builds'
text: "Build failed for ${{ github.repository }}"
fields: repo,message,commit,author,action,eventName,ref,workflow
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}Try It
Create GitHub Actions workflow. Add lint, test, build jobs. Configure keystore secrets. Set up Play Console service account. Deploy to internal/production tracks.
# Local fastlane
bundle exec fastlane android internalCI/CD mastery
- Create GitHub Actions workflow with lint, test, build jobs
- Configure keystore in GitHub Secrets
- Set up Play Console service account
- Deploy to internal testing track on main branch
- Deploy to production on version tags
- Add version bump workflow
- Configure Slack notifications
- Test with Fastlane locally
- Implement rollout strategy (10%, 50%, 100%)
- Add build caching for faster CI
GitHub Actions: lint → test → build → deploy. Keystore in secrets (base64 encoded). Play Console service account for deployment. Internal track for main, production for tags. Fastlane as alternative. Version bump via workflow_dispatch.
Resources
- GitHub Actions Android: https://github.com/android-actions
- Upload to Play: https://github.com/r0adkll/upload-google-play
- Fastlane Android: https://docs.fastlane.tools/platforms/android/
- Play Console API: https://developers.google.com/android-publisher