CI/CD Strategies for Android

0/3 in this phase0/52 across the roadmap

📖 Concept

CI/CD (Continuous Integration / Continuous Delivery) automates building, testing, and deploying Android apps. At the senior level, you're expected to design and maintain CI/CD pipelines.

CI pipeline stages:

1. Lint & Static Analysis  (2 min)
2. Unit Tests              (3 min)
3. Build Debug APK         (5 min)
4. Instrumented Tests      (10 min)
5. Screenshot Tests        (5 min)
6. Build Release Bundle    (5 min)
7. Deploy to Internal      (2 min)
Total: ~30 min for full pipeline

Key CI/CD practices:

  • PR checks: Lint + unit tests on every PR (fast feedback)
  • Merge checks: Full test suite + build on merge to main
  • Nightly: E2E tests, performance benchmarks
  • Release: Staged rollout (1% → 10% → 50% → 100%)

Tools:

  • GitHub Actions / GitLab CI — Pipeline definition
  • Firebase App Distribution — Internal test builds
  • Play Console Internal Testing — Staged releases
  • Danger / Detekt — Automated code review comments
  • Gradle Build Cache — Speed up CI builds with remote caching

💻 Code Example

codeTap to expand ⛶
1# GitHub Actions CI workflow for Android
2# .github/workflows/android-ci.yml
3
4name: Android CI
5
6on:
7 pull_request:
8 branches: [main]
9 push:
10 branches: [main]
11
12jobs:
13 lint-and-test:
14 runs-on: ubuntu-latest
15 steps:
16 - uses: actions/checkout@v4
17
18 - name: Set up JDK 17
19 uses: actions/setup-java@v4
20 with:
21 java-version: '17'
22 distribution: 'temurin'
23
24 - name: Cache Gradle
25 uses: actions/cache@v4
26 with:
27 path: |
28 ~/.gradle/caches
29 ~/.gradle/wrapper
30 key: gradle-${{ hashFiles('**/*.gradle*') }}
31
32 - name: Run Detekt (static analysis)
33 run: ./gradlew detekt
34
35 - name: Run Unit Tests
36 run: ./gradlew testDebugUnitTest
37
38 - name: Upload Test Results
39 if: always()
40 uses: actions/upload-artifact@v4
41 with:
42 name: test-results
43 path: '**/build/reports/tests/'
44
45 build:
46 needs: lint-and-test
47 runs-on: ubuntu-latest
48 steps:
49 - uses: actions/checkout@v4
50 - uses: actions/setup-java@v4
51 with: { java-version: '17', distribution: 'temurin' }
52
53 - name: Build Release Bundle
54 run: ./gradlew bundleRelease
55
56 - name: Upload Bundle
57 uses: actions/upload-artifact@v4
58 with:
59 name: release-bundle
60 path: app/build/outputs/bundle/release/
61
62# Detekt config for code quality
63# detekt.yml
64complexity:
65 LongMethod:
66 threshold: 30
67 LargeClass:
68 threshold: 300
69 ComplexCondition:
70 threshold: 4
71
72naming:
73 FunctionNaming:
74 functionPattern: '[a-z][a-zA-Z0-9]*'
75
76style:
77 MaxLineLength:
78 maxLineLength: 120

🏋️ Practice Exercise

Practice:

  1. Set up a GitHub Actions CI pipeline with lint, test, and build stages
  2. Configure Detekt for static analysis with custom rules
  3. Add screenshot test comparison to your CI pipeline
  4. Implement staged rollout using Play Console API
  5. Set up Gradle remote build cache for CI builds

⚠️ Common Mistakes

  • Not caching Gradle dependencies in CI — builds take 2-3x longer without cache

  • Running instrumented tests on every PR — too slow, run on merge or nightly

  • Not using build cache — incremental builds are much faster with remote cache

  • Manual release process — automate signing, bundle creation, and upload to Play Console

💼 Interview Questions

🎤 Mock Interview

Mock interview is powered by AI for CI/CD Strategies for Android. Login to unlock this feature.