Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions mobile/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<com.android.build.api.dsl.ApplicationExtension> {
namespace = "in.commandlinecoding.elephant"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
Expand All @@ -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

Expand All @@ -49,8 +56,47 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().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 {}
Loading