To sign your apk-file you need a key. Generate it!
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Remember your alias and password.
echo "android/app/*.jks" >> .gitignore
Copy a code below to <your_project>/android/app/build.gradle.
android {
...
signingConfigs {
release {
storeFile file("key.jks")
storePassword = "$System.env.STORE_PASSWORD"
keyAlias = "$System.env.KEY_ALIAS"
keyPassword = "$System.env.KEY_PASSWORD"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
Now build your apk-file locally! Export environment variables and start building.
export STORE_PASSWORD=<password>
export KEY_ALIAS=<alias>
export KEY_PASSWORD=<password>
flutter build apk --release
We don’t have a way of storing files securely in Github. So we’ll use base64 encode of the key and store that in Github secrets. Copy base64 code from the generated key.jks.
openssl base64 -in key.jks
Create a KEY_JKS secret and paste copied base64 code into the Value field. Also create secrets for your alias and password.
Settings > Secrets > New repository secret
Now create a Github action!
Actions > Skip this and set up a workflow yourself
Copy a code below to new yml-file.
name: CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
env:
KEY_JKS: ${{ secrets.KEY_JKS }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: 1.8
# if you use ndk
- run: echo "y" | sudo /usr/local/lib/android/sdk/tools/bin/sdkmanager --install "ndk;21.1.6352462" --sdk_root=${ANDROID_SDK_ROOT}
- uses: subosito/flutter-action@v1
with:
channel: 'stable' # or 'dev' or 'beta'
- run: echo $KEY_JKS | base64 -d > android/app/release.jks
- run: flutter pub get
- run: flutter test
- run: flutter build apk --release
- uses: actions/upload-artifact@v2
with:
path: build/app/outputs/flutter-apk/app-release.apk
Push any commit into your main branch. Enjoy!