From 6d7695379d9b474f1ff2dcf290347354d382c626 Mon Sep 17 00:00:00 2001 From: Suman Biswas Date: Sun, 19 Jul 2026 16:32:22 +0530 Subject: [PATCH] gradle update for split per abi --- mobile/android/app/build.gradle.kts | 60 +++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/mobile/android/app/build.gradle.kts b/mobile/android/app/build.gradle.kts index c68ed7d..337ec98 100644 --- a/mobile/android/app/build.gradle.kts +++ b/mobile/android/app/build.gradle.kts @@ -4,7 +4,16 @@ plugins { id("org.jetbrains.kotlin.android") } -android { +configurations.all { + exclude(group = "com.google.android.play", module = "core") + exclude(group = "com.google.android.play", module = "core-common") + exclude(group = "com.google.android.play", module = "feature-delivery") + exclude(group = "com.google.android.play", module = "app-update") + exclude(group = "com.google.android.play", module = "tasks") + exclude(group = "com.google.android.play", module = "split-install") +} + +configure { namespace = "in.commandlinecoding.elephant" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion @@ -24,10 +33,8 @@ android { buildTypes { getByName("release") { - // Using debug signing for release config as requested in your original setup signingConfig = signingConfigs.getByName("debug") - - // Critical for tree-shaking and stripping out unneeded classes + isMinifyEnabled = true isShrinkResources = true @@ -49,8 +56,47 @@ tasks.withType().configureEach } } -afterEvaluate { - configurations.all { - exclude(group = "com.google.android.play") +val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86_64" to 3) + +androidComponents { + onVariants { variant -> + variant.outputs.forEach { output -> + val abi = output.filters.find { + it.filterType == com.android.build.api.variant.FilterConfiguration.FilterType.ABI + }?.identifier + val baseAbiCode = abiCodes[abi] + if (baseAbiCode != null) { + // Multiplies main version code by 10 and appends the specific architecture suffix matching formula + output.versionCode.set((output.versionCode.get() ?: 1) * 10 + baseAbiCode) + } + } } } + +project.afterEvaluate { + tasks.configureEach { + if (name.contains("minifyReleaseWithR8") || name.contains("minifyReleaseWithProguard") || name.contains("dexBuilderRelease")) { + doFirst { + logger.lifecycle("FOSS SANITIZER: Active. Sweeping intermediate files for non-free binaries...") + + val searchDirs = listOf( + File(project.layout.buildDirectory.asFile.get(), "intermediates/classes/release"), + File(project.layout.buildDirectory.asFile.get(), "intermediates/javac/release") + ) + + for (dir in searchDirs) { + if (dir.exists()) { + dir.walkTopDown().forEach { file -> + if (file.isDirectory && file.absolutePath.endsWith("com/google/android/play/core")) { + file.deleteRecursively() + logger.lifecycle("Successfully removed vendor-shaded tracking package: ${file.absolutePath}") + } + } + } + } + } + } + } +} + +dependencies {} \ No newline at end of file