Skip to content

Instantly share code, notes, and snippets.

@nestorsgarzonc
Last active October 22, 2024 00:51
Show Gist options
  • Select an option

  • Save nestorsgarzonc/72ef1c640b8d04c8d0c31d0f1fedcbc6 to your computer and use it in GitHub Desktop.

Select an option

Save nestorsgarzonc/72ef1c640b8d04c8d0c31d0f1fedcbc6 to your computer and use it in GitHub Desktop.
Github action for android deployment using flutter
name: Flutter CD - Deployment Android
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
jobs:
flutter_build_android:
name: Build Android APK
runs-on: ubuntu-latest
steps:
- name: Checkout the branch
uses: actions/checkout@v4
- name: Setup Flutter SDK
uses: subosito/flutter-action@v2
with:
channel: 'stable'
cache: true
- name: Cache Pub Dependencies
uses: actions/cache@v3
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-${{ hashFiles('pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pub-
- name: Get packages
run: flutter pub get
- name: Decode Keystore
env:
ENCODED_STRING: ${{ secrets.encodedStoreFile }}
run: |
echo $ENCODED_STRING > keystore-b64.txt
base64 -d keystore-b64.txt > keystore.jks
- name: Build Release APK
env:
storePassword: ${{ secrets.storePassword }}
keyAlias: ${{ secrets.keyAlias }}
keyPassword: ${{ secrets.keyPassword }}
run: flutter build apk --flavor YOUR_FLAVOR --obfuscate --split-debug-info=YOUR_PATH
- name: Build Release AppBundle
env:
storePassword: ${{ secrets.storePassword }}
keyAlias: ${{ secrets.keyAlias }}
keyPassword: ${{ secrets.keyPassword }}
run: flutter build appbundle --flavor YOUR_FLAVOR --obfuscate --split-debug-info=YOUR_PATH
- name: Get release file aab path
id: releaseAab
run: echo "aabfile=$(find build/app/outputs/bundle -name '*.aab')" >> $GITHUB_OUTPUT
- name: Get release file apk path
id: releaseApk
run: echo "apkfile=$(find build/app/outputs/apk -name '*.apk')" >> $GITHUB_OUTPUT
- name: Upload Release Build to Artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: ${{ steps.releaseApk.outputs.apkfile }}
- name: Upload AppBundle to Internal Testing
uses: wzieba/step-google-play@v3
with:
serviceAccountJson: ${{ secrets.GOOGLE_PLAY_AUTH }}
packageName: com.example.app
source: build/app/outputs/bundle/release/app-release.aab
track: internal
@nestorsgarzonc
Copy link
Author

Modify the build.gradle sign section as folloging:

try {
                storeFile file("../keystore.jks")
                storePassword System.getenv("storePassword")
                keyAlias System.getenv("keyAlias")
                keyPassword System.getenv("keyPassword")
            } catch (Exception ignored) {
                storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
                storePassword keystoreProperties['storePassword']
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment