Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code signing and minification to release APKs #15

Merged
merged 22 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
739aee5
Merge pull request #3 from arafaysaleem/release
arafaysaleem Jun 7, 2021
8894420
ci(Actions): Update flutter action in release workflow
arafaysaleem Jun 7, 2021
e662cac
ci(Actions): Fix errors
arafaysaleem Jun 7, 2021
e7bb85d
ci(Actions): Include hotfix branches as triggers for Test PR
arafaysaleem Jun 7, 2021
62bbe5b
Merge pull request #4 from arafaysaleem/release
arafaysaleem Jun 7, 2021
46e6499
ci(Actions): Remove obfuscation from test builds
arafaysaleem Jun 7, 2021
c92a835
ci(Actions): Fix inputs for bump tag action in release action
arafaysaleem Jun 7, 2021
b6dfce2
ci(Actions): Fix token for bump tag action in release workflow
arafaysaleem Jun 7, 2021
f989bd5
ci(Actions): Fix token for upload artifact action
arafaysaleem Jun 7, 2021
3db54a0
ci(Actions): Fix regex for upload artifact pattern matching
arafaysaleem Jun 8, 2021
eaa6ed1
ci(Actions): Remove push triggers and rename to PR test
arafaysaleem Jun 8, 2021
cad9b7c
ci(Actions): add an ignore path to github workflows dir
arafaysaleem Jun 8, 2021
7500797
ci(Actions): split build apks and change output apks directory
arafaysaleem Jun 8, 2021
196b509
Merge pull request #11 from arafaysaleem/hotfix/fix-release-CI
arafaysaleem Jun 8, 2021
be898b0
build(Gradle): Add gradle signing config
arafaysaleem Jun 8, 2021
d29ffef
ci(Actions): Add apk signing to release workflow
arafaysaleem Jun 8, 2021
214ad8c
ci(Actions): Add missing runs-on tag in google drive action
arafaysaleem Jun 8, 2021
4696d1f
ci(Actions): Convert test build from release to debug
arafaysaleem Jun 8, 2021
382232d
Merge pull request #13 from arafaysaleem/ci/fix-release-workflow
arafaysaleem Jun 8, 2021
1ccb0ec
build(Gradle): Minify code using proguard
arafaysaleem Jun 8, 2021
69004ad
ci(Actions): Adjust labeler config for gradle changes
arafaysaleem Jun 8, 2021
b448da1
Merge pull request #14 from arafaysaleem/build/add-apk-minification
arafaysaleem Jun 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ chores:
- any: ['.gitignore']

native/android:
- any: ['android']
- any: ['android/**/*']

gradle:
- any: ['android']
- any: ['android/**/*']
139 changes: 94 additions & 45 deletions .github/workflows/PR-merge-build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,105 @@ on:
branches:
- master
types: [ closed ]
paths-ignore: ['doc/**','**.md','.gitignore','Prototype/**']
paths-ignore: ['doc/**','**.md','.gitignore','Prototype/**','.github/**']

workflow_dispatch:

name: Build Release APK
jobs:
build:
flutter-setup:
if: github.event.pull_request.merged == true
name: build-release
name: Run Codegen and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- name: Checkout Flutter Stable Channel
uses: subosito/flutter-action@v1
with:
channel: 'stable'
- name: Get Pub Dependencies
run: flutter pub get
- name: Run build runner for codegen files
run: flutter packages pub run build_runner build --delete-conflicting-outputs
- name: Run Dart Analyzer
run: flutter analyze .
- name: Generate splitted release apks
run: flutter build apk --obfuscate --split-debug-info=/ez_tickets_app/debug_trace --split-per-abi
- name: Bump version and push tag
id: generate_tag
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.EZ_TICKETS_APP_TOKEN }}
default-bump: minor # major, minor, patch, false
custom-release-rules: "chore:patch:Chore Tasks,hotfix:minor:Bug Fixes,
refact:patch:Refactors,docs:patch:Documentation Changes,
build:patch:Build System/Dependency Upgrades"
- name: Upload release apk to artifacts
uses: ncipollo/[email protected]
with:
tag: "${{ steps.generate_tag.outputs.new_tag }}"
artifacts: "build/app/outputs/apk/release/*.apk"
name: Release ${{ steps.generate_tag.outputs.new_tag }}
body: ${{ steps.generate_tag.outputs.changelog }}
token: ${{ secrets.EZ_TICKETS_APP_TOKEN }}
- name: Upload apks to google drive
uses: mkrakowitzer/actions-googledrive@1
with:
upload-from: ./build/app/outputs/apk/release/
upload-to: APKS/ez_tickets_app/
skicka-tokencache-json: ${{ secrets.SKICKA_TOKENCACHE_JSON }}
google-client-id: ${{ secrets.DRIVE_CLIENT_ID }}
google-client-secret: ${{ secrets.DRIVE_CLIENT_SECRET }}
remove-outdated: 'false'
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- name: Checkout Flutter Stable Channel
uses: subosito/[email protected]
with:
channel: 'stable'
- name: Get Pub Dependencies
run: flutter pub get
- name: Run build runner for codegen files
run: flutter packages pub run build_runner build --delete-conflicting-outputs
- name: Run Dart Analyzer
run: flutter analyze .

assemble-release:
name: Setup signing keys
runs-on: ubuntu-latest
env:
ENCRYPTED_KEYSTORE: ${{ secrets.ENCRYPTED_KEYSTORE }}
KEYSTORE_FILENAME: ${{ secrets.KEYSTORE_FILENAME }}
KEYSTORE_PASSPHRASE: ${{ secrets.KEYSTORE_PASSPHRASE }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
steps:
- uses: actions/checkout@v2
- name: Load and decrypt keystore #destination of both should be the android folder
run: |
echo "$ENCRYPTED_KEYSTORE" > "$KEYSTORE_FILENAME.asc"
gpg -d --passphrase "$KEYSTORE_PASSPHRASE" --batch "$KEYSTORE_FILENAME.asc" > "./android/$KEYSTORE_FILENAME"
- name: Generate key properties
run: |
echo "storeFile=$KEYSTORE_FILENAME" > ./android/key.properties
echo "storePassword=$KEYSTORE_PASSPHRASE" > ./android/key.properties
echo "keyPassword=$KEYSTORE_PASSPHRASE" > ./android/key.properties
echo "keyAlias=$KEY_ALIAS" > ./android/key.properties

build-release:
needs: [flutter-setup,assemble-release]
name: Build Release APKS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- name: Checkout Flutter Stable Channel
uses: subosito/[email protected]
with:
channel: 'stable'
- name: Get Pub Dependencies
run: flutter pub get
- name: Run build runner for codegen files
run: flutter packages pub run build_runner build --delete-conflicting-outputs
- name: Generate splitted release apks
run: flutter build apk --target-platform android-arm,android-arm64 --split-per-abi --obfuscate --split-debug-info=./ez_tickets_app/debug_trace

release-artifacts-upload:
needs: [build-release]
name: Upload APKS to release artifacts
runs-on: ubuntu-latest
steps:
- name: Bump version and push tag
id: generate_tag
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: minor # major, minor, patch, false
custom_release_rules: "ci:patch:CI/CD,chore:patch:Chore Tasks,hotfix:minor:Bug Fixes,refact:patch:Refactors,docs:patch:Documentation Changes,build:patch:Build System/Dependency Upgrades"
- name: Upload release apk to artifacts
uses: ncipollo/[email protected]
with:
tag: "${{ steps.generate_tag.outputs.new_tag }}"
artifacts: "build/app/outputs/flutter-apk/*.apk"
name: "Release ${{ steps.generate_tag.outputs.new_tag }}"
body: "${{ steps.generate_tag.outputs.changelog }}"
token: ${{ secrets.GITHUB_TOKEN }}

google-drive-upload:
needs: [build-release]
name: Upload APKS to google drive
runs-on: ubuntu-latest
steps:
- name: Upload apks to google drive
uses: mkrakowitzer/actions-googledrive@1
with:
upload-from: ./build/app/outputs/flutter-apk/
upload-to: APKS/ez_tickets_app/
skicka-tokencache-json: ${{ secrets.SKICKA_TOKENCACHE_JSON }}
google-client-id: ${{ secrets.DRIVE_CLIENT_ID }}
google-client-secret: ${{ secrets.DRIVE_CLIENT_SECRET }}
remove-outdated: 'false'
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ name: Test PR and Push
on:
pull_request:
branches: [release,dev,master]
paths-ignore: ['doc/**','**.md','.gitignore','Prototype/**']
push:
branches: [feature/**]
paths-ignore: ['doc/**','**.md','.gitignore','Prototype/**']
paths-ignore: ['doc/**','**.md','.gitignore','Prototype/**','.github/**']
jobs:
build:
name: Test APK
Expand All @@ -26,4 +23,4 @@ jobs:
- name: Run Dart Analyzer
run: flutter analyze .
- name: Attempt release build generation
run: flutter build apk --split-per-abi
run: flutter build apk --debug
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ app.*.map.json
*.g.dart
*.freezed.dart
*.gr.dart

#keystore
*.jks
23 changes: 20 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
println keystorePropertiesFile
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
compileSdkVersion 30

Expand All @@ -42,11 +49,21 @@ android {
multiDexEnabled true
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Flutter
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }