All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.tinkoff.plugins.buildmetrics.android.metrics.AndroidAabMetrics.kt Maven / Gradle / Ivy

package ru.tinkoff.plugins.buildmetrics.android.metrics

import ru.tinkoff.plugins.buildmetrics.api.metrics.Metric
import ru.tinkoff.plugins.buildmetrics.android.utils.BundleTool
import ru.tinkoff.plugins.buildmetrics.api.labels.Label
import java.io.File

internal fun androidAabMetrics(
    aabFiles: List,
    bundleTool: BundleTool,
): List> = mutableListOf>().apply {
    addAll(aabDownloadSizeMetrics(aabFiles = aabFiles, bundleTool = bundleTool))
}

private fun aabDownloadSizeMetrics(
    aabFiles: List,
    bundleTool: BundleTool,
): List> = aabFiles.flatMap { aab ->
    bundleTool.getSize(
        apksPath = generateApksFromAab(aabFile = aab, bundleTool = bundleTool).path
    ).map { (sizeType, sizeValue) ->
        Metric(
            name = "application_package_size_bytes",
            value = sizeValue,
            labels = listOf(
                Label(name = "file_name", value = aab.name),
                Label(name = "size_type", value = sizeType.lowercase().trim()),
            )
        )
    }
}

private fun generateApksFromAab(
    aabFile: File,
    bundleTool: BundleTool,
): File = File(aabFile.parentFile, "${aabFile.nameWithoutExtension}.apks").also { apks ->
    if (apks.exists()) {
        check(apks.delete()) {
            "Failed to delete file '$apks'."
        }
    }
    check(bundleTool.buildApks(bundlePath = aabFile.path, outputPath = apks.path) == 0) {
        "Failed to generate apks file from bundle '$aabFile'."
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy