From d6be66e0b07eba345c7563af263aa05581ffb8e3 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Wed, 11 Oct 2023 17:38:02 +0330 Subject: [PATCH] Change android signing --- .github/workflows/build.yml | 45 ++++++++++++++---------------------- android/app/build.gradle | 46 +++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ccf0afb..fd37ebf1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,12 +4,12 @@ on: branches: - main tags: - - "v*" + - 'v*' paths-ignore: - - "**.md" - - "docs/**" - - ".github/**" - - "!.github/workflows/build.yml" + - '**.md' + - 'docs/**' + - '.github/**' + - '!.github/workflows/build.yml' pull_request: branches: - main @@ -64,15 +64,15 @@ jobs: - name: Setup Flutter uses: subosito/flutter-action@v2 with: - flutter-version: "3.13.x" - channel: "stable" + flutter-version: '3.13.x' + channel: 'stable' cache: true - name: Setup Java if: startsWith(matrix.platform,'android') uses: actions/setup-java@v3 with: - distribution: "zulu" + distribution: 'zulu' java-version: 11 - name: Setup Flutter Distributor @@ -114,23 +114,12 @@ jobs: - name: Setup Signing Properties if: startsWith(matrix.platform,'android') - env: - ANDROID_SIGNING_KEY_ALIAS: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }} - ANDROID_SIGNING_KEY_PASSWORD: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }} - ANDROID_SIGNING_STORE_PASSWORD: ${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }} - ANDROID_SIGNING_KEY: ${{ secrets.ANDROID_SIGNING_KEY }} run: | - cd android - pwd - touch signing.properties - echo $ANDROID_SIGNING_KEY | base64 -d > release.keystore - echo "keystore.path=release.keystore" > release.properties - echo keystore.password="$ANDROID_SIGNING_STORE_PASSWORD" >> release.properties - echo key.alias="$ANDROID_SIGNING_KEY_ALIAS" >> release.properties - echo key.password="$ANDROID_SIGNING_KEY_PASSWORD" >> release.properties - cp release.* app/ - cat release.properties - cd .. + echo "${{ secrets.ANDROID_SIGNING_KEY }}" | base64 --decode > android/key.jks + echo "storeFile=$(pwd)/android/key.jks" > android/key.properties + echo "storePassword=${{ secrets.ANDROID_SIGNING_STORE_PASSWORD }}" >> android/key.properties + echo "keyPassword=${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}" >> android/key.properties + echo "keyAlias=${{ secrets.ANDROID_SIGNING_KEY_ALIAS }}" >> android/key.properties - name: Release ${{ matrix.platform }} env: @@ -258,7 +247,7 @@ jobs: uses: 8Mi-Tech/delete-release-assets-action@main with: github_token: ${{ secrets.GITHUB_TOKEN }} - tag: "draft" + tag: 'draft' deleteOnlyFromDrafts: false - name: Create or Update Draft Release @@ -268,8 +257,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: files: ./out/* - name: "draft" - tag_name: "draft" + name: 'draft' + tag_name: 'draft' prerelease: true upload-release: @@ -309,7 +298,7 @@ jobs: with: prerelease: ${{ env.CHANNEL == 'dev' }} tag_name: ${{ github.ref_name }} - body_path: "./release.md" + body_path: './release.md' files: ./out/* - name: Create service_account.json diff --git a/android/app/build.gradle b/android/app/build.gradle index f8fdeb9e..bf3ba2c7 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -11,6 +11,24 @@ if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } +boolean hasKeyStore = false + +def keystoreProperties = new Properties() +def keystorePropertiesFile = rootProject.file('key.properties') +if (keystorePropertiesFile.exists()) { + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) + hasKeyStore = true +} else { + println "+++" + println "No keystore defined. The app will not be signed." + println "Create a android/key.properties file with the following properties:" + println "storePassword" + println "keyPassword" + println "keyAlias" + println "storeFile" + println "+++" +} + def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,11 +39,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -def keystoreProperties = new Properties() -def keystorePropertiesFile = rootProject.file('release.properties') -if (keystorePropertiesFile.exists()) { - keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) -} apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" @@ -61,24 +74,33 @@ android { abi { enable true reset() + //noinspection ChromeOsAbiSupport include "x86_64", "armeabi-v7a", "arm64-v8a" universalApk true } } - signingConfigs { - release { - keyAlias keystoreProperties['key.alias'] - keyPassword keystoreProperties['key.password'] - storeFile keystoreProperties['keystore.path'] ? file(keystoreProperties['keystore.path']) : null - storePassword keystoreProperties['keystore.password'] + if (hasKeyStore) { + signingConfigs { + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile file(keystoreProperties['storeFile']) + storePassword keystoreProperties['storePassword'] + } } } + buildTypes { release { - signingConfig signingConfigs.release + if (hasKeyStore) { + signingConfig signingConfigs.release + } else { + signingConfig signingConfigs.debug + } ndk { + //noinspection ChromeOsAbiSupport abiFilters "x86_64", "armeabi-v7a", "arm64-v8a" } }