How to reduce size of strings.xml - android

I have an android app which was 0.3MB in size before adding support for more languages.
When i added support for 10 other languages using "values-es", "values-ar" etc.... the app size tripled.
This is understandable as my app uses alot of text. And i assume the app size was caused by the new folders and strings.xml files of each locale values folder.
Is there ant way to reduce the sizes of these files. I've removed unnecessary spacing and formatting that they are hardly visible. I have also been using proguard.

you can release separate apk files for each of your locales, you can mark them in the developer console i think to be just for specific languages. each apk would have just a single language.
But this is not something i would recommend. 0.9 megabytes is nothing today on the market. don't worry about it and just build it as a single apk. It is much easier to manage the updates and everything developer-wise if its just a single apk.

The only way to reduce the size of strings.xml is to remove unused strings. you can find unused strings easily by using Android LINT

Related

How to load an online android module at run-time?

Is it possible to split my Android apk of 512MB into different parts or modules.
Compile small part of it into a release Apk (small Apk size) for Play Store.
Then fetch the remaining parts or modules from online or your own server during first time install on a device.
Thats:
Small Apk to Google Play Store
Fetch remaining big files after first install.
I am using Android Studio.
Of course you can, that can be easily achieved if you got to split heavy resources(like images, videos, databases). Here you must write some logic which will download that resources and will work with them after a successful download.
I cant imagine a situation when you must to split a code in a separate module, compiled code is light and dont increase apk size so much as another resources. Code can become heavy when there is a lot of code from libraries, in that case I suggest you to learn about Proguard Shrink.
Also you can learn why in android is not possible to load java modules in runtime. On of the reasons is performance given by JIT
Here a is workaround with ndk How do I import shared object libraries at runtime in Android?

Tried everything : Still how can I reduce my apk size ?

How can I reduce my apk size more efficiently ? I know this is a frequently asked question but I didn't get much help with the resources available.
I have tried "lint" from Android Studio, it removed several resources but the apk size has not shrinked that much.
I have used "PngCrush" to compress png files, but it did not helped much (Only 150Kb reduced). Is there any better solution for reducing png file sizes ?
I am now opting to use ProGuard. Is it safe ? What amount of size will it be able to deduct from my apk ?
My APK size is currently 17 MB, I want to bring it down to less than 10 MB. Are there other solutions available ? Thanks in advance.
Proguard should be the way to go because it removes the unused code as well as renames the variable/method name to something like a,b,c,aa,ab.
What amount can be reduced? It depends. My situation is a 10M apk was reduced to 8M using Proguard.
Is it safe? One of the purpose of Proguard is that it obfuscate the code, making it hard for reverse engineering.
you can use following methods :
1) use proguard : set minifyEnabled true
2) Remove unused resources : set shrinkResources true
3) Remove everything that you are not using
4) If you are using librarires ,try finding the snippet that you are
really using,if you dont find any such version,try fiddling with the
required class directly in your app instead of importing whole library
5) Use vector drawable instead of pngs for your small icons and
drawables
6) Reduce png images clarity to point where it have same
effect to human eye ,while its size is reduced heavily
7) Try generating resources or draws on runtime instead of storing it before
hand
Progaurd is totally safe,make sure you keep a raw backup of ur work before using proguard ,also use proper rules for all libraries and other important resources and code , before you activate proguard.Generally libraries provided default proguard rules for thier libraries

Does including JAR in android project affects the size of apk

I am including a JAR file into my android project and is using some of the classes present in the JAR (not all the JAR).
I want to know, the size of the apk that is generated after building the project is dependent on the JAR I have included or it is dependent only on the classes that I have used in my project.
The entire jar will be included in the APK. You may have used some classes, but they are internally dependent to a large extent. Also, the classes which are not used get included.
An APK is an Android application package file. Each Android application is compiled and packaged in a single file that includes all of the application’s code (.dex files), resources, assets, and manifest file. The APK file is basically a .zip file, so there’s no way of compressing its size any further.
Memory space on smartphones is often a competitive area, now that most users are storing music, video, messages are more, in addition to downloading apps. The smaller you make your APK, the better it is for the user, and that may be a deciding factor on whether to download your app, versus a similar app that takes up more phone memory.
Tips for reducing file size
There are a number of recommendations for reducing static footprint. You can choose the ones that fit best for your own particular needs. Proguard is the one option.
Check HERE for more details of reducing the apk size.
ProGuard
A tool for code shrinking, like ProGuard, will significantly reduce the static foot print. Note that it is very important to re-test all of the application after applying ProGuard since it may change the application behavior.
As ProGuard replaces the application symbols, to make the code difficult to read, it is important that you retain the symbol mapping, so that you can translate a stack trace back to the original symbols if you have to investigate a crash in your application.
Yes. By default the whole jar goes into the apk.
You can use ProGuard to strip all the stuff you don't need during compilation.

Is there a way to add or change Android apps language after packaging it into an APK?

In the case of a windows application(EXE/DLL), we can change or add language resources within the binary without re-compiling it. Can the same be done in case of an Android application? Is there any editor available to make this happen?
My plan is to develop the application in English and then release it to the sales department, where they will be responsible for the localization of the application without compiling and packaging it into a new APK. I just want to split the development part and localization part of the app.
The correct way to localize is to create a string resource for your base language and then have that localized and reimported into your project for every language that you support.
Much more detail can be found in the Localization documentation.
I don't believe there is a safe/supported way to inject localized strings into your app after it's been built.
No. You can not, because once your apk is signed then modifying it after this (you can always do that as apk is just a zip file) will corrupt the signed binary.
When having multiple languages with your application you have to build them into the application itself. Android uses XML files to store strings used within your application. Android allows you to add language localization files containing local specific strings. You can't do this without recompiling your project so you'll want to do it as a future update or right from the start. But you can't have the marketing department do it, that's just not a good idea.
As others have said, the short answer is no. The long(er) answer is sort of. If you pack all your language resources into remote XML that can be updated from the web, then with a little bit of forethought you can do all sorts of live updates to your app's strings, graphics, etc.
So if you want to use the standard R.string method for everything it will be a little difficult. I think it's possible to do something funky with a dynamic classloader for the assets and static dex classes (basically classes of data with just inline byte arrays that can be decoded after). However that would still require compiling. See Custom Class Loading in Dalvik for more info.
Another approach would be more of a standard Java implementation. Java has a class known as ResourceBundle. You could create a ResourceBundle from a property file (key-value plain text, or even property xml). Then these files could be loaded outside the apk, via a network connection or sdcard or other file type resource and deleted as necessary. You will have to write the loader code for it, but that's going to happen with any solution. This solution will be less performant and outside the standard design methods for android but it will solve the problem being asked to solve. Like you won't be able to use R.string or #string/whatever for any of these resources but I think you may be able to write an adapter to such resources (like your own TextView extension and whatever that would allow all of this). It's a matter mostly of how much work you want to invest in solving this actual problem.
Honestly I would opt for trying to distribute whole apks with only the targeted language if you are trying to save space, but then there is no way to change locale for the app at runtime :(

How to reduce App (.apk) Size

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

Categories

Resources