Skip to content

Instantly share code, notes, and snippets.

@empeje
Last active August 8, 2024 09:30
Show Gist options
  • Select an option

  • Save empeje/9ebad8499a9f251cac14124db90e2f33 to your computer and use it in GitHub Desktop.

Select an option

Save empeje/9ebad8499a9f251cac14124db90e2f33 to your computer and use it in GitHub Desktop.
Firebase App Distribution Android - GitLab CI
.android_build:
image: openjdk:8-jdk
stage: build # kind of job
variables:
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.3"
ANDROID_SDK_TOOLS: "4333796"
FLUTTER_VERSION: "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_1.22.6-stable.tar.xz"
before_script:
# Install Firebase
- curl -L https://firebase.tools/bin/linux/latest -o firebase
- chmod +x firebase
- mv firebase /usr/local/bin/
# Install Android
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
## temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
# Install Flutter
- wget --output-document=flutter-sdk.tar.xz $FLUTTER_VERSION
- tar -xf flutter-sdk.tar.xz
- export PATH=$PATH:$PWD/flutter/bin
- flutter precache
- flutter packages get
- flutter clean
stages:
- test # All jobs related for testing such as Unit Test
- build # All jobs related for building app for iOS and Android
####
#### flutter debug
####
flutter_build_debug: #Job name
extends: .android_build
retry: 2
script:
- flutter build apk --flavor dev
artifacts:
paths:
- build/app/outputs/flutter-apk/app-dev-release.apk
####
#### flutter release
####
flutter_build_release: #Job name
extends: .android_build
retry: 2
script:
- flutter build apk --release --flavor prod
- flutter build appbundle --release --flavor prod
- ./bin/app_distribution.sh
artifacts:
paths:
- build/app/outputs/flutter-apk/app-prod-release.apk
- build/app/outputs/bundle/prodRelease/app-prod-release.aab
#!/usr/bin/env bash
RELEASE_NOTE=$(git log -1 --oneline --format=%s)
firebase appdistribution:distribute build/app/outputs/flutter-apk/app-prod-release.apk \
--token "$FIREBASE_TOKEN" \
--app "$APP_ID" \
--release-notes "$RELEASE_NOTE" --testers-file testers.txt
@hendisantika
Copy link
Copy Markdown

Can I see your gitlab-ci.yml @empeje ?

Thanks

@empeje
Copy link
Copy Markdown
Author

empeje commented Aug 2, 2024

Sure, added @hendisantika

@hendisantika
Copy link
Copy Markdown

Thanks @empeje

@hendisantika
Copy link
Copy Markdown

Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd)
  on green-1.saas-linux-small-amd64.runners-manager.gitlab.com/default JLgUopmM, system ID: s_deaa[2](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L2)ca09de7
Preparing the "docker+machine" executor
00:13
Using Docker executor with image openjdk:8-jdk ...
Pulling docker image openjdk:8-jdk ...
Using docker image sha256:b27[3](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L3)004037cc3af245d8e08cfbfa672b93ee7dcb289736c82d0b58936fb71702 for openjdk:8-jdk with digest openjdk@sha256:86e863cc57215cfb181bd319736d0baf625fe8f150577f9eb58bd937f5[4](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L4)52cb8 ...
Preparing environment
00:05
Running on runner-jlguopmm-project-[5](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L5)9400063-concurrent-0 via runner-jlguopmm-s-l-s-amd[6](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L6)4-1722753054-e5c41afa...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/kominfo-pemuda-persis/anaonline-super-app/.git/
Created fresh repository.
Checking out e0850cf1 as detached HEAD (ref is dev)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Executing "step_script" stage of the job script
00:00
Using docker image sha256:b2[7](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L7)3004037cc3af245d8e08cfbfa672b93ee7dcb2[8](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L8)9736c82d0b58936fb71702 for openjdk:8-jdk with digest openjdk@sha256:86e863cc57215cfb181bd319736d0baf625fe8f150577f[9](https://gitlab.com/kominfo-pemuda-persis/anaonline-super-app/-/jobs/7500782883#L9)eb58bd937f5452cb8 ...
$ apk update
/bin/bash: line 150: apk: command not found
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

@hendisantika
Copy link
Copy Markdown

I am using

  image: amazoncorretto:21-alpine-jdk

The error would be:

$ chmod +x firebase
$ mv firebase /usr/local/bin/
$ apt-get --quiet update --yes
/bin/sh: eval: line 160: apt-get: not found
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 127

@empeje
Copy link
Copy Markdown
Author

empeje commented Aug 4, 2024

That's because you're using alpine-jdk, you need to use apk update and apk add command to install applications.

@hendisantika
Copy link
Copy Markdown

$ apk add --quiet update --yes
apk-tools 2.14.4, compiled for x86_64.
apk: unrecognized option: yes
usage: apk add [<OPTIONS>...] CONSTRAINTS...
Description:
  apk add adds or updates given constraints to WORLD (see world) and commit
  changes to disk. This usually involves installing new packages, but may also
  cause other changes to the installed packages.
Global options:
  -f, --force           Enable selected --force-* options (deprecated)
  -i, --interactive     Ask confirmation before performing certain
                        operations
  -p, --root ROOT       Manage file system at ROOT
  -q, --quiet           Print less information
  -U, --update-cache    Alias for '--cache-max-age 1'
  -v, --verbose         Print more information (can be specified twice)
  -V, --version         Print program version and exit
  -X, --repository REPO
                        Specify additional package repository
  --allow-untrusted     Install packages with untrusted signature or no
                        signature
  --arch ARCH           Temporarily override architecture
  --cache-dir CACHEDIR  Temporarily override the cache directory
  --cache-max-age AGE   Maximum AGE (in minutes) for index in cache before
                        it's refreshed
  --force-binary-stdout
                        Continue even if binary data will be printed to the
                        terminal
  --force-broken-world  DANGEROUS: Delete world constraints until a solution
                        without conflicts is found
  --force-missing-repositories
                        Continue even if some of the repository indexes are
                        not available
  --force-non-repository
                        Continue even if packages may be lost on reboot
  --force-old-apk       Continue even if packages use unsupported features
  --force-overwrite     Overwrite files in other packages
  --force-refresh       Do not use cached files (local or from proxy)
  --keys-dir KEYSDIR    Override directory of trusted keys
  --no-cache            Do not use any local cache path
  --no-check-certificate
                        Do not validate the HTTPS server certificates
  --no-interactive      Disable interactive mode
  --no-network          Do not use the network
  --no-progress         Disable progress bar even for TTYs
  --print-arch          Print default arch and exit
  --progress            Show progress
  --progress-fd FD      Write progress to the specified file descriptor
  --purge               Purge modified configuration and cached packages
  --repositories-file REPOFILE
                        Override system repositories, see repositories
  --timeout TIME        Timeout network connections if no progress is made
                        in TIME seconds
  --wait TIME           Wait for TIME seconds to get an exclusive repository
                        lock before failing
Commit options:
  -s, --simulate        Simulate the requested operation without making any
                        changes
  --clean-protected     Do not create .apk-new files in configuration
                        directories
  --overlay-from-stdin  Read list of overlay files from stdin
  --no-scripts          Do not execute any scripts
  --no-commit-hooks     Skip pre/post hook scripts (but not other scripts)
  --initramfs-diskless-boot
                        Used by initramfs when it's recreating root tmpfs
Add options:
  --initdb              Initialize a new package database
  -l, --latest          Always choose the latest package by version
  -u, --upgrade         Upgrade PACKAGES and it's dependencies
  -t, --virtual NAME    Create virtual package NAME with given dependencies
  --no-chown            Do not change file owner or group
For more information: man 8 apk-add
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

@empeje
Copy link
Copy Markdown
Author

empeje commented Aug 8, 2024

That's expected, you need to figure out how to use the apk in alpine and beyond the guide I have provided in the YuoTube video. I usually like to help, but I'm a bit time poor right now, so I suggest you to learn how to use it by yourself for now.

@hendisantika
Copy link
Copy Markdown

Ok Thanks @empeje

I created new one with this:

image: "ghcr.io/cirruslabs/flutter:3.22.3"

stages:
  - build
  - deploy

variables:
  FIREBASE_CLI_VERSION: "11.5.0"
  GRADLE_USER_HOME: "/builds/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/.gradle"

cache:
  key: "${CI_JOB_NAME}"
  paths:
    - .gradle/wrapper
    - .gradle/caches

before_script:
  - flutter doctor
  - flutter pub get

build:
  stage: build
  script:
    - flutter build apk --release
    - ls -la build/app/outputs/flutter-apk/
  artifacts:
    paths:
      - build/app/outputs/flutter-apk/app-release.apk

deploy:
  stage: deploy
  dependencies:
    - build
  only:
    - main
  script:
    - curl -sL https://firebase.tools | bash
    - firebase appdistribution:distribute build/app/outputs/flutter-apk/app-release.apk --app $FIREBASE_APP_ID --token $FIREBASE_TOKEN --groups "testers" --release-notes "New version of ANA ONLINE is available"

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