From 79374ca7a536b926e14406c3790cd79355096cd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Mon, 14 Oct 2024 14:36:38 +0200
Subject: [PATCH] Improve build process, according to "Build multiple APKs"
 https://developer.android.com/build/configure-apk-splits

---
 .gitlab-ci.yml           |  2 ++
 android/app/build.gradle | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 24c8063..469c971 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -25,6 +25,7 @@ android:build-debug:
     # build flutter app
     - flutter packages get
     - flutter clean
+    - flutter build apk --debug --split-per-abi
     - flutter build apk --debug
     # prepare artifact
     - find . -name "*.apk" # where is my apk?
@@ -63,6 +64,7 @@ android:build-release:
       else
         flutter packages get
         flutter clean
+        flutter build apk --release --split-per-abi
         flutter build apk --release
       fi
     # prepare artifact
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 1c18897..1a07a0e 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -62,6 +62,31 @@ android {
             signingConfig signingConfigs.release
         }
     }
+
+    splits {
+        abi {
+            reset()
+            include('armeabi-v7a', 'x86', 'x86_64')
+        }
+    }
+}
+
+ext.abiCodes = [
+    'armeabi-v7a': 1,
+    'x86': 2,
+    'x86_64': 3
+]
+
+import com.android.build.OutputFile
+
+android.applicationVariants.all { variant ->
+  variant.outputs.each { output ->
+    def baseAbiVersionCode = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
+
+    if (baseAbiVersionCode != null) {
+      output.versionCodeOverride = baseAbiVersionCode * 1000 + variant.versionCode
+    }
+  }
 }
 
 flutter {
-- 
GitLab