Someone asked me in interview how to reduce APK file size, and my answer was to manage the resources and also to manage the libraries that I am using and remove any unused libraries, but he told me that there are other ways to reduce APK file size
Can anyone tell me what are these ways ?
You can reduce APk size using following way.
Follow this steps to reduce your APK file size.
1st step :
make sure that you have enabled minify in your release
buildType in build.gradle
file :
buildTypes {
release {
minifyEnabled true
}
}
by doing this you are also enabling proguard, so you need to add proguard rules for using libraries in your project. for example this are the proguard rules for retrofit2 :
-dontwarn okio.**
-dontwarn javax.annotation.**
you can add this two rules in your proguard-rules.pro
file.
2nd step :
make sure that you have enabled resource shrinking in your release
buildType in build.gradle
file :
buildTypes {
release {
shrinkResources true
}
}
so your final release
scope in build.gradle
file should look like this :
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
3rd step :
some libraries that you may have used in your project have some additional resources for different countries and languages. for example a library could have two string.xml files, one for english language and one for japanese language. but you are only supporting english language in your application, so you don't need those japanese strings.
to do this open your build.gradle file and add this line :
resConfigs "en"
to your defaultConfig scope under android scope :
android {
...
defaultConfig {
...
resConfigs "en"
}
}
4th step :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With