From b6b27681f044856a90147a3629e972c48e29b8da Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 22:17:23 +0900 Subject: [PATCH] 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" } } }