Android Product Development (four)--Reduce apk size

Source: Internet
Author: User

With the development of mobile technology, a variety of cool effect of the update, in our pursuit of UI and UE at the same time a less than the problem of neglect gradually exposed, that is, the apk file is growing, there may be children's shoes will say now is WiFi environment, apk file increase a few m is not a big deal of the problem, There is some truth in this, but as a developer we are not the reason we think we can ignore the problem. Optimizing the APK size is also an important aspect of optimizing our app experience, although it may not be that important.

So what are the reasons for our apk files getting bigger and larger?

    • Multi-screen is the problem of adaptation, the diversification of mobile devices led to an app need n-clock different size settings, thereby increasing the installation files of the type and size of the resource files;

    • A variety of development frameworks, development tools to improve, although it is convenient for our developers to repeatedly build the wheel, but this also indirectly increases the size of the installation file;

    • In the pursuit of various animation, UI effect of the intrinsic needs, the obvious more cool UI, UE effect will objectively increase or decrease the size of the APK file;

    • Lack of communication between developers, too much redundant code causes the APK file to increase;

    • In order to meet the requirements of performance and security, add. So library;

Well, now that we know why our apk file is getting bigger, we can have a targeted solution, in order to better explain the problem, here I simply listed the APK file composition:

    • source code files, etc.

    • Resource files include various layout files in apk file, resource files, picture files, native files, etc.

    • Local code files This is mainly referred to as the. so file

So after knowing the composition of the apk file, how to reduce the size of the APK file is very simple

Reducing the size of the APK file is already a very important thing. As we know the components of the APK file, we can do some optimizations for the installation files based on these components. Here are some of the ways I've summarized how to reduce the size of the APK file:

How to optimize the source file:

    • Master good coding habits, reuse code, for some repetitive code logic reuse;

    • Using Proguard to confuse code, optimize, compress (it's not just a cow rub obfuscation tool is also great in code optimization).

      • By reducing references to useless code libraries, a common scenario is that some code libraries are not needed, but they are still referenced in the code, and the consequence is that useless code libraries are also compiled into the apk file;

      • Regular code review, this is a very important work, can be the team members familiar with each other's code can also find out some of the bugs you don't see and reduce some useless code;

      • Do some work like code lint, Android studio has provided such a function, regular code execution lint operation is a good habit;

How to optimize resource files:

    • For some unnecessary equipment size, do not need all the equipment (mainly see product requirements)

    • The resource files, mainly the picture resources are compressed;

    • Some UI effects can use code rendering instead of picture resources;

    • The reuse of resource files, such as two pages background image of the same color, you can re-use background images, set different color;

How to optimize local code files:

    • Limit the number of CPU architectures supported by your app, and allow your app to support Armabi and x86 architectures in the current Android ecosystem;

    • Reuse so library files as much as possible;

Finally, the emphasis on a piece of compression work, in fact, all of the above-mentioned to reduce the size of the APK is the most important skill in the compression of the image work. In general, the effect of image compression on the size of the APK is less than 50% of all your efforts to reduce the APK effort, so to reduce the size of the APK to consider how to reduce the size of the picture it.

Here is a good picture compression site: https://tinypng.com/support for JPG and PNG image resource compression.

We can specifically test the compression of different size picture resources:

You can see that when the picture resource is more than 100k compression rate is about 65%, in the 10k+ picture resources on the same very cow rub, when the picture resources less than 10k with the size of the picture decreases, gradually reduced.

Later specifically in our APK file is compressed in this way again, the size of the APK file from 11.86M to 10.52M, the effect of the APK file reduction is still very obvious.

Summarize

The way to reduce the APK file is relatively, experience requires a certain trade-offs, design is to find the best solution in a constraint set. Obviously the size of the APK file is a constraint. Don't be afraid to relax a constraint in order to make multiple aspects better. You need to consider all aspects of the app as a whole, not just a few.

In addition to product development technology, skills, practice interested students can refer to my:
Android Product Development (i) –> Practical development Code
Android product Development (ii) –> start Page optimization
Android Product Development (iii) –> base class activity

This article synchronizes to GitHub: Https://github.com/yipianfengye/androidProject, Welcome to star and follow

Android Product Development (four)--Reduce apk size

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.