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
}
}
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
}
}