Skip to content

Instantly share code, notes, and snippets.

@Oskang09
Last active January 4, 2023 09:41
Show Gist options
  • Save Oskang09/07dacd3825dbc1c1fa398e6b67885560 to your computer and use it in GitHub Desktop.
Save Oskang09/07dacd3825dbc1c1fa398e6b67885560 to your computer and use it in GitHub Desktop.
Gitlab Android APK CI Example
staging:
image: node:10.19.0 # can replace to your image
stage: deploy
only:
- master # target to branch?
script:
# apply ssh private key
- "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# package installation
- apt-get update -qy
- apt-get install -y python-dev python-pip
- apt install android-sdk -y
- apt install unzip default-jdk -y
# setup android sdkmanager tools
- wget https://dl.google.com/android/repository/$ANDROID_CLI_VERSION.zip
- unzip $ANDROID_CLI_VERSION.zip
- rm -rf /usr/lib/android-sdk/tools
- mv tools /usr/lib/android-sdk
# aws credential setup ( optional )
- pip install awscli
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
# android sdk installation
- wget -qO- https://storage.googleapis.com/flutter_infra/releases/stable/linux/$FLUTTER_VERSION.tar.xz | tar xvf - -J
- export PATH="$PATH:`pwd`/flutter/bin"
- flutter precache
- flutter packages get
- yes | flutter doctor --android-licenses || true
# build and deploy
- echo $ANDROID_KEYSTORE | base64 -d > /builds/Getbutler/worker-mobile/android/app/keystore.jks
- flutter build apk --flavor sandbox -t lib/main-sandbox.dart
- mv ./build/app/outputs/apk/sandbox/release/app-sandbox-release.apk /build/app/outputs/apk/sandbox/release/workerapp.apk
# optional
- aws s3 sync ./build/app/outputs/apk/sandbox/release/ s3://xx.xxxxx.com --exclude "*" --include "workerapp.apk"

This method should work on both flutter and react native just replacing the build command to yours.

Android Licenses

For react native, android license have to use the sdkmanager command insteadof flutter doctor --android-licenses.

- yes | /usr/lib/android-sdk/tools/bin/sdkmanager --license || true

Secret Key

  • SSH_PRIVATE_KEY - private key for getting private packages ( optional )
  • ANDROID_CLI_VERSION - Android sdkmanager tools version ( sdk-tools-linux-4333796 )
  • AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY - Aws credentails ( optional )
  • FLUTTER_VERSION - flutter sdk version ( flutter_linux_1.17.4-stable, can be found at https://flutter.dev/docs/development/tools/sdk/releases )
  • ANDROID_KEYSTORE - Base64 encoded keystore binary ( you can get it using openssl base64 -A -in filename.keystore. )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment