Hey i'm using a native library for my android application and it compiles to an so file of size 2.5 mb. i tried different ways to reduce the size but did not get a solution. i was wondering if i could find out what exactly is causing the size issue by going through the so file is this possible.
When you are using AndroidStudio you can just open the apk in it. It will you the content of it and what size the diffrent components have.
You can analyze APK with APK Analyzer by drag APK file into Android Studio. It will show detail of classes and resources size.
https://developer.android.com/studio/build/apk-analyzer
https://github.com/google/bloaty can show you a breakdown of where the space is being spent. It can also diff two binaries to show you the changes, which is really helpful when trying to figure out what effect any flags you tweak might be having.
First of all , I am using android studio for development of android app. I have build an android app for OCR using tesseract library. The app is currently working great and giving desire output but my problem is with its size. The size of the build app is 30 MB which is high compared to other OCR app available. I have tried "minifyenabled = true" but it reduce just 300 kb of size. So my question is how to reduce size of my app?
You can use APK splits to build smaller versions of your app that target individual device architectures. For an example of this, see the San Angeles demo project.
You can get a further reduction by removing the libpngt.so/libjpgt.so files if your app doesn't need them.
Using ProGuard may help too.
Regarding tesseract lib size have a look at options provided by tesseract itself. Description is in article less is better. Be aware some of options are experimental, so check your OCR quality.
Use the 3.01 version of Tesseract .trainddata files.
How to reduce size of tessdata used for TessBaseAPI in android?
Read the answer in http://stackoverflow.com/questions/25101534/reducing-android-app-apk-size you will get the solution. And for the record always try to reduce duplicating codes
App sizes largely increases due to 3rd party libraries and images. Please have a look at what all images you have used and try reducing their sizes where all possible.
One more thing you can do is use Lint to check for unused resources and remove them if any.
Just right click on app directory -> Analyze -> Run Inspection By name
and then type in Unused resources.
Size of your android app plays a decisive role in application development where devices work on pay-by-the-byte plans.
So, here are a few ways of reducing the size of your android app.
Avoid using Pngs ( use vector images ) .
Use pngcrush for compressing the png .
Url: https://pmt.sourceforge.io/pngcrush/
Try to get most of the images from a server rather than keeping them in source code.
Use Dynamic Delivery concept to load on-demand features during runtime.
Avoid using third party #libraries which can be done simply by a few lines of code.
"Android Size Analyzer" this #plugin helps you in reducing the size of the app by giving you suggestions.
Switch to Android App #Bundles from #APKs while publishing app or releasing updates. In this way , App is built based on CPU architecture (ABI), Language and Screen Density of the device.
Documentation: https://developer.android.com/studio/build/configure-apk-splits
Important :
Set minifyEnabled and shrinkResources to true in your gradle.
If you want to read more, you can visit my linkedIn profile post.
Url : https://www.linkedin.com/posts/abhishek-gupta-9b32b816b_android-app-development-activity-6609095411581972480-heF8
I want to reduce the size of my android application, so I started exploring what is there in my apps .apk file, strange I want images from hololighttheme in the resources folder, although I selected none in themes while creating my project in eclipse. Can anyone help to prevent these default images creeping into my application?
Make sure you are not keeping unnecessary images in drawable folders. The APK file is basically a .zip file, so there’s no way of compressing its size any further.
I can give you following tips which will help you reduce the size of APK file.
Use ProGuard to obfuscate the code,which will not only will provide you security but also it will shrink the code to great extent.
Switch off all debug logs when you are releasing app in production.
static final boolean debug = false;
if (debug) {
Log.v(TAG,"blah blah blah");
}
Use a tool such as OptiPNG or PNGCrush reducing PNG file size while still ensuring image quality.
This question already has answers here:
How to reduce App (.apk) Size
(23 answers)
Closed 8 years ago.
I have developed a simple Android application. Its APK size is 8MB. Can anyone tell me how to reduce the APK size?
Try enabling ProGuard, even without obfuscation. It will remove unused Java code from your dependencies.
See if you have unneeded dependencies - JARs that you've added but aren't using
Check your resources for large images or other files. You may want to change their format or resolution, or remove them if they're not in use.
Optimize your final APK (after ProGuard) with Facebook's ReDex. This should reduce the code size as well as potentially improve performance.
1) First you need to enable Proguard even without obfuscation. It will remove unused Java code from your dependencies.
2) Second, use 9-patch images instead of very high resolution images.
3) Remove some unnecessary code and also JAR files that haven't be used.
4) Ensure you are using .png images instead of .jpg.
5) Use different images for different screen resolutions.
6) Check your layout folder for unnecessary XML files
You can use Lint to check for things like unused resources or unnecessary views in your layout files. Additionally, you can use Proguard to obfuscate your code, which in doing so will reduce class and variable name lengths.
Help!
When I install my app on the phone to test, it is showing up to be a HUGE size, 11.35 MB. It is a very simple app that lets user browse through fun-facts. The only reason I can think of is that there are 14 JPEG files in the drawables which serve as background images of the fun-facts. The average size of these is about 500 KB.
I'd like to trim the size of my app, so as not to use up the precious resources on the user's device. Other than just getting rid of the pictures, are there ways to optimize the size of apk file?
EDIT: The pictures are photos taken by me using the Android phone itself.
Other answers mention shrinking images. You might also consider trying ProGuard to shrink your bytecode. Here's an article on applying ProGuard to an Android app.
I would recommend that you compress the .jpg files as much as possible, this should greatly reduce the size of your .apk file. A tool such as Paint.NET which is free should help you do this. It has great resizing options.
Make sure that your jpg's aren't stored in any higher resolution than necessary. A nice Android phone has a screen resolution of 1920x1200 or 2560x1440 (circa 2015)800 x 480 , so your backgrounds shouldn't contain any more pixels than that (unless your app supports some kind of zooming). Also, are the backgrounds photographs? If not, you may find that using a vector based image format like svg, or one with a dynamic palette like gif, will reduce the file size even more.
UPDATE
With the introduction of Support Library 23.2, now you can replace many of your Image assets with SVG ( w/ or w/o animations) to reduce the apk size further.
ORIGINAL
This could be a late reply but might be helpful for future users.
Refer this link.
To summarise the page, it mentions below key points that will help reduce the apk size in totality:
Use ProGaurd
Remove any debug info you have in the app ( statements such as Log.i()). They can be wrapped in a condition which is only enabled while testing out the application.
Use recommended media formats
Image: PNG orJPG
Audio: AAC
Video: H264 AVC
Compress images using OptiPNG or PNGCrush
Use 9patch to scale images
Find unused resources using this tool and remove them.
Avoid using multiple resources to achieve the same functionality. The resources do not only limit to images but extend to APIs. At times a singular API can provide multiple results instead of using two or three different APIs. Duplicated strings and assets are also a waste of space.
Convert to WebP which will significantly reduce the app size
It reduced the app size of my app which was 40 mb to 25 mb
Steps:
Right click on res
convert to WebP
What it does: It reduces the size to png to WebP format. Quality is also not destroyed
Beyond optimizing images, I also found it useful to verify the Support Libraries you use. I have a relatively simple application targeting platforms with API >=10, still my APK ended up being 2.2M, or after using ProGuard, 1.4M. When I looked into the APK, the code was 1.5M and there were a lot of additional resources included (abc_*) I knew nothing about.
Then I found this: https://developer.android.com/tools/support-library/features.html
Turns out I did not need appcompat-v7, only support-v4, and making this change to my dependencies reduced the APK size to 1.7M (0.9M with ProGuard).
Understandably, the Support Libraries carry a lot of extra (code and resource), so making sure you use only the ones you need might help.
(Even though -0.5M is not significant for a 11M app, I am posting this here because I kept ending up on this page while searching for a solution...)
Use tinypng compress your project's png or
jpg format image files, It can greatly reduce the size of the image
without loss in image quality;
Some images use tinypng compress may distortion, you can convert
these images to webP format, use 智图 or
iSparta can convert other format to webP;
Use Lint check no use resources and delete it;
Four Ways and your app size will become from 11.35 MB to near about 5 MB.
First, check the app components via App Analyzer (an inbuilt feature of Android studio), Simply click on Build on the top and click Analyze APK. It will show you everything what components apk is using.
Enable Proguard
Enable ShrinkResource
resConfigs (Name it, like if your app is in only one language eg English then simply specify resConfigs "en")
Convert all Images from .png or.jpg to webp (Most Important).
Steps to achieve these steps.
1 & 2. For Proguard and ShrinkResource
In gradle, simply add
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
}
For resConfigs
defaultConfig {
applicationId "com.goparties.gpuser"
minSdkVersion 19
targetSdkVersion 27
resConfigs "en"
}
TO convert all Images from .png or.jpg to webp
Very easy process: Just right click on the drawable folder(drawable,drawable-hdpi, drawable-xhdpi etc) and click on convertToWebP (last option).
Min SDK version should be 18.
Here we go: Now analyze your app size.
Bingo !!!!!!
One more thing to add on image file size - different algorithms can have a significant effect on the final size. I found that Yahoo's www.smushit.com is a lot more effective (at least for .png) than compressors and codecs I have on my computer right now.
There are two things I can point out from experience.
If you use eclipse to create apk file then the resources are duplicated (atleast it happened in my case), you can try using ant and build.xml to create the apk and compare the size.
Also look into aliasing the resources. The link for it is here.
I think this post would give you a better idea on all the possible methods to use to reduce your apk size by a huge margin.
I will give you an excerpt of the same.
Use only the required libraries from Google Play Services.
Apply ProGuard to your app.
Minify and shrink.
Adopt vector drawables.
Use the android lint.
Split your apk based on the architectures
Adding resConfigs in your gradle files to specify localization languages.
This strips away all other string files that could’ve been added by other libraries in languages you don’t even support.
I know i am late here to answer this question but i reduce my app size using below techniques so i want to share these things with all.
1)- Use WebP images instead of Jpeg images, it will provide huge impact on apk size if you are using multiple images.
2)-Use VectorDrawables if you are using simple small icons in your app.
3)- Use View's tint property in xml to avoid multiple same icons but Different in color.
search DrawableTint and TintableImageview
4)- Use 9-patch images and avoid duplication of image or anything in the app code.
Below are the links to refer to reduce APK size.
https://developer.android.com/topic/performance/reduce-apk-size.html
https://developer.android.com/studio/build/configure-apk-splits.html#configure-split
https://developer.android.com/training/multiple-apks/index.html
WebP image format: provides lossy compression (like JPEG) as well as transparency (like PNG) but can provide better compression than either JPEG or PNG
Convert images to WebP
Along with the above most upvoted answers, I would like to answer with latest tools from Google's Android Studio.
Google recently has introduced the Android App Bundle in which playstore automatically delivered optimized version of apk to end devices.
Now developers just has to generate Signed Bundle, and upload to play store, dev job is done. Don't forget always use SVG images.
Also please have look into Deliver Features On-Demand with Dynamic Features
Here is what you can do for reduce build size by Images (Also can work for iOS)
Here I am sharing the great tool called “OPTIPNG ” (you can download from here )which will help us to reduced the build specially by using Images, It will reduced the Image size for PNGs we are using without degrading quality (Resolution and color) of the image.
Example – If your image size is off 698 KB then It will simpley reduced size to 564 KB
Here is the execution steps for OPTIPNG 0.7.5
1) Terminal -> CD /YourLocal path of OPTIPNG
2) type “./configure”
3) type ”sudo make install”
Intallation should be done now
4) type ” optipng /your image path
You will get result in byte and can also check your size
You could also try http://www.webresizer.com/resizer/ Its an online tool, Did a pretty good job for me.
I used Trimage image compressor for compressing images and reducing the size of apk.It has good compression rate,easy to use,retains the quality of image and is also available in Ubuntu.Beside this i enabled ProGuard and worked on Lint issues to reduce APK size.
Following are the ways to reduce the app size. In detail is explained in the following link.
https://medium.com/#fahimsakri/put-your-apks-on-diet-cc3f40843c84#.m860q8s1u
Proguard
vector drawables
Apk splits
Optimize png images
Remove unused resources
9-patch images
Compress Jpeg images
Remove debug information
Avoid duplications
Use lint extensively
Reuse resource whenever possible
Recommended Media formats
You can reduce apk size by del R.class and replaces the reference to constant.
See this:
https://github.com/mogujie/ThinRPlugin
APK contains a zip file of all the things that your mobile application has including Java class files, resource files among others.
One of the simple ways to make your APK smaller is to reduce the number and size of the resources it contains. In particular, you can remove resources that your app no longer uses, and you can use scalable Drawable objects in place of image files.
Use MinifyEnable true
and ShrinkResources true
MinifyEnabled will reduce your code as it compresses it.
While shrinkResources shrink the resources.
To use ShrinkResources you have to set minifyEnbled true.
There are a few techniques:
Proguard
Unnecessary Resources
Webp images
Signed apk
Android App Bundle
For detailed explanation:
https://stackoverflow.com/a/63988744/13928327
use SVG images instead of jpg in order to reduce the apk size.
put your image files in the database .. so that the users of your app can download it from the database and it will reduce the app size dramatically..