From d617a9a3dc1074f5b9775d9da642c7c7786ee5d5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 1 Mar 2023 09:57:52 +0100 Subject: [PATCH] Split APK per ABI --- .github/workflows/build.yml | 2 +- .github/workflows/maestro.yml | 2 +- app/build.gradle.kts | 51 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2587e16a87..1e9468fe83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: with: name: elementx-debug path: | - app/build/outputs/apk/debug/app-debug.apk + app/build/outputs/apk/debug/*.apk - uses: rnkdsh/action-upload-diawi@v1.3.1 id: diawi with: diff --git a/.github/workflows/maestro.yml b/.github/workflows/maestro.yml index f9921a88fa..3ff2b401d2 100644 --- a/.github/workflows/maestro.yml +++ b/.github/workflows/maestro.yml @@ -28,7 +28,7 @@ jobs: - uses: mobile-dev-inc/action-maestro-cloud@v1.3.1 with: api-key: ${{ secrets.MAESTRO_CLOUD_API_KEY }} - app-file: app/build/outputs/apk/debug/app-debug.apk + app-file: app/build/outputs/apk/debug/app-universal-debug.apk env: | USERNAME=maestroelement PASSWORD=${{ secrets.MATRIX_MAESTRO_ACCOUNT_PASSWORD }} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7b8f71184f..fe91885570 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,6 +14,9 @@ * limitations under the License. */ +@file:Suppress("UnstableApiUsage") + +import com.android.build.api.variant.FilterConfiguration.FilterType.ABI import extension.allFeatures import extension.allLibraries @@ -45,6 +48,28 @@ android { vectorDrawables { useSupportLibrary = true } + + // Keep abiFilter for the universalApk + ndk { + abiFilters += listOf("armeabi-v7a", "x86", "arm64-v8a", "x86_64") + } + + // Ref: https://developer.android.com/studio/build/configure-apk-splits.html#configure-abi-split + splits { + // Configures multiple APKs based on ABI. + abi { + // Enables building multiple APKs per ABI. + isEnable = true + // By default all ABIs are included, so use reset() and include to specify that we only + // want APKs for armeabi-v7a, x86, arm64-v8a 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("armeabi-v7a", "x86", "arm64-v8a", "x86_64") + // Generate a universal APK that includes all ABIs, so user who installs from CI tool can use this one by default. + isUniversalApk = true + } + } } signingConfigs { @@ -138,6 +163,32 @@ android { } } +androidComponents { + // map for the version codes last digit + // x86 must have greater values than arm + // 64 bits have greater value than 32 bits + val abiVersionCodes = mapOf( + "armeabi-v7a" to 1, + "arm64-v8a" to 2, + "x86" to 3, + "x86_64" to 4, + ) + + onVariants { variant -> + // Assigns a different version code for each output APK + // other than the universal APK. + variant.outputs.forEach { output -> + val name = output.filters.find { it.filterType == ABI }?.identifier + + // Stores the value of abiCodes that is associated with the ABI for this variant. + val abiCode = abiVersionCodes[name] ?: 0 + // Assigns the new version code to output.versionCode, which changes the version code + // for only the output APK, not for the variant itself. + output.versionCode.set((output.versionCode.get() ?: 0) * 10 + abiCode) + } + } +} + // Knit apply { plugin("kotlinx-knit")