From b6b27681f044856a90147a3629e972c48e29b8da Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 22:17:23 +0900 Subject: [PATCH 1/6] Allow generating different apks per cpu type. Reduces apk size considerably. --- app/build.gradle | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8b9632e6..6c43d6f4 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,6 +76,27 @@ android { } } + splits { + // Configures multiple APKs based on ABI. + abi { + // Enables building multiple APKs per ABI. + enable true + + // By default all ABIs are included, so use reset() and include to specify that we only + // want APKs for x86 and x86_64. + + // Resets the list of ABIs that Gradle should create APKs for to none. + reset() + + // Specifies a list of ABIs that Gradle should create APKs for. + include "x86", "x86_64", "arm64-v8a", "armeabi-v7a" + + // Specifies that we want to also generate a universal APK that includes all ABIs. + universalApk true + } + } + + android.applicationVariants.all { variant -> if (variant.flavorName != "github") return variant.outputs.all { output -> @@ -84,15 +105,32 @@ android { // def versionCode = variant.versionCode def flavor = variant.flavorName - def suffix = "${versionName}-${flavor}_${builtType}" // eg. 19.1.0-github_debug or release + def flavorBuiltType = "${flavor}_${builtType}" + def suffix + // For x86 and x86_64, the versionNames are already overridden + if (versionName.contains(flavorBuiltType)) { + suffix = "${versionName}" + } else { + suffix = "${versionName}-${flavorBuiltType}" // eg. 19.1.0-github_debug or release + } if (builtType.toString() == 'release' && project.hasProperty("pre")) { buildConfigField("boolean", "isPre", "true") - // append latest commit short hash for pre-release - suffix = "${versionName}.${getGitHash()}-${flavor}" // eg. 19.1.0.b123456-github + + flavorBuiltType = "${getGitHash()}-${flavor}" + + // For x86 and x86_64, the versionNames are already overridden + if (versionName.contains(flavorBuiltType)) { + suffix = "${versionName}" + } else { + // append latest commit short hash for pre-release + suffix = "${versionName}.${flavorBuiltType}" // eg. 19.1.0.b123456-github + } } output.versionNameOverride = suffix - outputFileName = "barinsta_${suffix}.apk" + def abi = output.getFilter(com.android.build.OutputFile.ABI) + // println(abi + ", " + versionName + ", " + flavor + ", " + builtType + ", " + suffix) + outputFileName = abi == null ? "barinsta_${suffix}.apk" : "barinsta_${suffix}_${abi}.apk" } } } From 04879819c50fa2cbe2699ded5eeb4e60cd8824c2 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 4 Apr 2021 02:29:43 +0900 Subject: [PATCH 2/6] Enable splits only if it is a release build and skip if 'noAbiSplits' is passed as project prop --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 6c43d6f4..33ab6b4d 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,7 +80,7 @@ android { // Configures multiple APKs based on ABI. abi { // Enables building multiple APKs per ABI. - enable true + enable !project.hasProperty("noAbiSplits") && gradle.startParameter.taskNames.contains("Release") // By default all ABIs are included, so use reset() and include to specify that we only // want APKs for x86 and x86_64. From 0d0c5fa3208a2f51560b8d028cc5fbde29827a22 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 9 May 2021 23:42:59 +0900 Subject: [PATCH 3/6] Build, sign, upload multiple apks --- .github/workflows/github_pre_release.yml | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/github_pre_release.yml b/.github/workflows/github_pre_release.yml index 22bf3620..ff479941 100644 --- a/.github/workflows/github_pre_release.yml +++ b/.github/workflows/github_pre_release.yml @@ -14,20 +14,20 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - + - name: set up JDK 1.8 uses: actions/setup-java@v1 with: java-version: 1.8 - + - name: Grant execute permission for gradlew run: chmod +x gradlew - + - name: Build Github unsigned pre-release apk run: ./gradlew assembleGithubRelease --stacktrace --project-prop pre - + - name: Sign APK - uses: r0adkll/sign-android-release@v1 + uses: ammargitham/sign-android-release@v1.1 # ID used to access action output id: sign_app with: @@ -36,18 +36,19 @@ jobs: alias: ${{ secrets.ALIAS }} keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} keyPassword: ${{ secrets.KEY_PASSWORD }} - + - name: Get current date and time id: date run: echo "::set-output name=date::$(date +'%Y%m%d_%H%M%S')" - - # Create artifact + + # Create artifact - name: Create apk artifact uses: actions/upload-artifact@v2 with: name: barinsta_pre-release_${{ steps.date.outputs.date }} - path: ${{steps.sign_app.outputs.signedReleaseFile}} - + # path: ${{steps.sign_app.outputs.signedReleaseFile}} + path: app/build/outputs/apk/github/release/*-signed.apk + # Send success notification - name: Send success Telegram notification if: ${{ success() }} @@ -56,8 +57,9 @@ jobs: to: ${{ secrets.TELEGRAM_BUILDS_CHANNEL_TO }} token: ${{ secrets.TELEGRAM_BUILDS_BOT_TOKEN }} message: "${{ github.workflow }} ${{ github.job }} #${{ github.run_number }} completed successfully.\nURL: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" - document: ${{steps.sign_app.outputs.signedReleaseFile}} - + # document: ${{steps.sign_app.outputs.signedReleaseFile}} + document: app/build/outputs/apk/github/release/*-signed.apk + # Send failure notification - name: Send failure Telegram notification if: ${{ failure() }} From 437a123f5cbd52c11ae2f6bc7a7cc128c4d6ac6d Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 10 May 2021 00:01:26 +0900 Subject: [PATCH 4/6] Update sign apk action --- .github/workflows/github_pre_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github_pre_release.yml b/.github/workflows/github_pre_release.yml index ff479941..b5c99aca 100644 --- a/.github/workflows/github_pre_release.yml +++ b/.github/workflows/github_pre_release.yml @@ -27,7 +27,7 @@ jobs: run: ./gradlew assembleGithubRelease --stacktrace --project-prop pre - name: Sign APK - uses: ammargitham/sign-android-release@v1.1 + uses: ammargitham/sign-android-release@v1.1.1 # ID used to access action output id: sign_app with: From 870eac1b6a56efca25630aa76a8000109ab9d959 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 10 May 2021 00:21:59 +0900 Subject: [PATCH 5/6] Fix multiple apk build not triggered --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 4b000c17..f720044f 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,7 +86,7 @@ android { // Configures multiple APKs based on ABI. abi { // Enables building multiple APKs per ABI. - enable !project.hasProperty("noAbiSplits") && gradle.startParameter.taskNames.contains("Release") + enable !project.hasProperty("noAbiSplits") && !gradle.startParameter.taskNames.isEmpty() && gradle.startParameter.taskNames.get(0).contains('Release') // By default all ABIs are included, so use reset() and include to specify that we only // want APKs for x86 and x86_64. From ae356d660193b2dd7db8d40b72fc78c4de8de5cd Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 10 May 2021 00:54:06 +0900 Subject: [PATCH 6/6] Add prop to explicitly split apks instead of default --- .github/workflows/github_pre_release.yml | 2 +- app/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github_pre_release.yml b/.github/workflows/github_pre_release.yml index b5c99aca..9700fdfc 100644 --- a/.github/workflows/github_pre_release.yml +++ b/.github/workflows/github_pre_release.yml @@ -24,7 +24,7 @@ jobs: run: chmod +x gradlew - name: Build Github unsigned pre-release apk - run: ./gradlew assembleGithubRelease --stacktrace --project-prop pre + run: ./gradlew assembleGithubRelease --stacktrace --project-prop pre --project-prop split - name: Sign APK uses: ammargitham/sign-android-release@v1.1.1 diff --git a/app/build.gradle b/app/build.gradle index f720044f..d20884cf 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,7 +86,7 @@ android { // Configures multiple APKs based on ABI. abi { // Enables building multiple APKs per ABI. - enable !project.hasProperty("noAbiSplits") && !gradle.startParameter.taskNames.isEmpty() && gradle.startParameter.taskNames.get(0).contains('Release') + enable project.hasProperty("split") && !gradle.startParameter.taskNames.isEmpty() && gradle.startParameter.taskNames.get(0).contains('Release') // By default all ABIs are included, so use reset() and include to specify that we only // want APKs for x86 and x86_64.