kotlin - Why is my Android Debug APK size larger when setting minSdkVersion to 28? - Stack Overflow

admin2025-04-15  0

I’m working on an Android app and I recently updated the minSdkVersion to 28 (Android 9.0, Pie). After building a debug APK, I noticed that the APK size has increased significantly compared to when the minSdkVersion was lower.

It was 40 mb when changed min sdk to 28 it is now debug apk output is 90mb. Why?

Here’s the relevant portion of my build.gradle file:

android {
    namespace = "com.application.id.new"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.application.id.new"
        minSdk = 28
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"
    }

    buildTypes {
      release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
}

 externalNativeBuild {
            cmake {
                cppFlags("")
            }
        }

        ndk {
            // Configure the NDK version if needed
            version = "28.0.12674087"  // Choose the version that matches your setup
        }

    externalNativeBuild {
        cmake {
            path = file("CMakeLists.txt") // CMake build file path
        }
    }

I’m working on an Android app and I recently updated the minSdkVersion to 28 (Android 9.0, Pie). After building a debug APK, I noticed that the APK size has increased significantly compared to when the minSdkVersion was lower.

It was 40 mb when changed min sdk to 28 it is now debug apk output is 90mb. Why?

Here’s the relevant portion of my build.gradle file:

android {
    namespace = "com.application.id.new"
    compileSdk = 35

    defaultConfig {
        applicationId = "com.application.id.new"
        minSdk = 28
        targetSdk = 35
        versionCode = 1
        versionName = "1.0"
    }

    buildTypes {
      release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
}

 externalNativeBuild {
            cmake {
                cppFlags("")
            }
        }

        ndk {
            // Configure the NDK version if needed
            version = "28.0.12674087"  // Choose the version that matches your setup
        }

    externalNativeBuild {
        cmake {
            path = file("CMakeLists.txt") // CMake build file path
        }
    }

Share Improve this question asked Feb 4 at 14:53 Santhosh KumarSanthosh Kumar 5611 silver badge11 bronze badges 1
  • Yes, i tried it is shows classes.dex files takes high mb. Inside that material icons module takes little more around 20mb only. Also, i am using ndk also for my project i think it will be issue. i am updated my code. How to deal ndk not to increase my apk size. – Santhosh Kumar Commented Feb 4 at 14:57
Add a comment  | 

1 Answer 1

Reset to default 5

DEX files uncompressed in APKs when minSdk = 28 or higher AGP now packages DEX files uncompressed in APKs by default when minSdk = 28 or higher. This causes an increase in APK size, but it results in a smaller installation size on the device, and the download size is roughly the same.

https://developer.android.com/build/releases/past-releases/agp-4-2-0-release-notes#dex-files-uncompressed-in-apks-when-minsdk-=-28-or-higher

Add this code on your build.gradle.kts,

  packaging {
        // Exclude unnecessary resources like licenses
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }

        // Force DEX files to be compressed (reduce APK size)
        dex {
            useLegacyPackaging = true  // Compress DEX files
        }

        // Force native libraries to be compressed (reduce APK size)
        jniLibs {
            useLegacyPackaging = true  // Compress native libraries
        }
    }
转载请注明原文地址:http://www.anycun.com/QandA/1744712535a86575.html