I am facing a problem with app size in android.
The scenario is,
I developed my android app in Android Studio 2.0 and the size of apk was 23 MB.
After that, I upgraded my IDE to android studio 2.2 and with little code modification the size of apk boosted to 51 MB.
I tried with prorogued and Lint but no advantage.
Can Someone help me to tackle the issue.
1) Replace all of Images,Icons with vector drawable
2) Turn on pro guard like following goto build.gradleapp level
and put these lines
**shrinkResources true
minifyEnabled true**
3) Remove unused classes,drawable and methods and strings and use LINT's private method analyser which reduces method count
4) In android studio 2.2 and above they have added apk analyser tool in Build menu. Use that to analyse APk
5) if app size goes beyond 100mb use feature called split apk. there are two methods of spliting apk ABI and Density Splits
Do this changes in your build.gradle(Module:app)
file. It decreases the apk size almost (40-50)%.
android {
// Other settings
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
It reduces the size of classes.dex
files and res folder
.
It is recommended to that you should use webp
file format instead of BMP, JPG, PNG
for better compression.
For reference, you can use: https://developer.android.com/studio/write/convert-webp.html
For more details on apk compression you can refer:
https://developer.android.com/topic/performance/reduce-apk-size.html
Points to reduce APK size:
Make sure to do it
1. Use vector drawable
2. Use xml drawable to create simple view
3. Rotate images using xml drawable to reuse (eg. in case of arrow buttons)
4. Create drawable through code
5. Use aaptOptions { cruncherEnabled = false } to compress images
6. Use webP format for large images
7. Avoid enumerations and use @IntDef annotation
8. Use shrinkResources true in gradle to remove unused resources
9. Use resConfig “en” in gradle to remove other localization
Android Size Analyser Reduce apk size android Android Studio has the Android Size Analyser plugin that allows you to see which files are taking up the most space. To install the plugin
Select File > Setting (or, on Mac, Android Studio > Preferences. Scroll down to the plugins section. Click on the Marketplace tab. Look for the “Android Size Analyzer” plugin. To install the analyzer plugin, click the Install link. After installing the plugin, restart the IDE. To analyze your application, click Analyze> Analyze App Size in the menu bar. You will see something similar:
Use below Steps
Read More On Codeplayon Web Site 3. Proguard
Proguard can also be used to reduce the size of your application by removing unneeded classes and methods. This makes it difficult to reverse engineer your code.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro' }
}
3.Utilization of ShrinkResources
In the build, you will see the ShrinkResources method. Gradle file. This will eliminate resources that are not being used for the project.
It must be enabled by declaring that it is true. This method is available in build.Gradle file > createTypes > release > shrinkResources. Make it true.
buildTypes {
release {
shrinkResources true
}
}
You can delete any debug libraries you have in your app. This can be accomplished by using DebugImplementation when building a testing debug apk.
debugImplementation 'com.amitshekhar.android:debug-db:1.0.1'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.