App weight loss: Lean for resources and make it better!

Source: Internet
Author: User

Today to share with you is the Android slimming Dafa, the content is more comprehensive, for everyone in the future development to do a reference!

1th: Use a set of resources

This is the most basic rule, but it is very important. For a great log app, it's enough to just take a set of design drawings. Given the current resolution trend, it is recommended to take 720p resources and put them into the xhdpi directory. Compared to multiple sets of resources, only use 720P of a set of resources, in the visual difference is not small, many large companies of the product is the same, but can significantly reduce the size of resources, the way can also alleviate the designer's drawing workload. Note that this is not to say that directories that are not xhdpi are deleted, but that it is sufficient to keep a set of design resources.

2nd: Open minifyenabled Obfuscation code

The Gradle uses minifyenabled for proguard confusing configuration, which greatly reduces the size of the app:

  

In Proguard, the preservation of the symbol table has a significant effect on the size of the app and is not retained as appropriate, but it is recommended that you try to keep it for debugging.

3rd: Open shrinkresources to remove useless resources

The Gradle uses shrinkresources to remove useless resources, which works very well.

  

4th: Delete Useless language resources

Most applications do not need to support internationalization support in dozens of languages. Fortunately strong Gradle support language configuration, such as domestic applications only support Chinese:

  

5th: Using Tinypng lossy compression

The Android package itself does lossless compression of PNG, so it is necessary to use lossy compression like tinypng. The focus is tinypng use of intelligent lossy compression technology to minimize distortion in order to reduce the size of the picture, the effect is very good, highly recommended.

6th: Use JPG format

If the larger image is opaque, the JPG will have a significant advantage over the size of PNG, though not absolute, but will usually be reduced to half. In the Start page, the active page, and so on the large image display area with JPG will be very wise choice.

7th: Use WEBP format

WEBP support transparency, compression compared to JPG higher but the display effect is not lost in JPG, the official evaluation quality parameter equals 75 balance best. Relative to JPG, png,webp as a new image format, limited to the support of Android is not used in the mobile phone for a wide range of applications. Native support starts from Android 4.0+, but does not support the inclusion of transparency until Android 4.2.1+ supports the display of WEBP with transparency, especially when used.

8th: Reduce the large image

If after the above steps, there are some large drawings in your project, consider whether it is necessary to maintain such a large size, whether the appropriate reduction. In fact, because of the designers out of the picture, we get a lot of pictures can be properly narrowed and the visual impact is very small.

9th: Overlay The big picture in the third library

Some of the third libraries cite some large images but are not actually used by us, so we can consider using 1x1 transparent images to cover them. You might be a little uncomfortable, because your drawable under a 1x1 picture that contains some inexplicable names ...

10th: Delete The so under the ARMABLE-V7 package

Basically armable so is compatible with ARMABLE-V7, ARMABLE-V7A Library will have a great improvement on graphics rendering, if there is no such requirements, can be streamlined. Here does not rule out a very small number of equipment will be crash, May and different so have a certain relationship, please be sure to test thoroughly before release.

11th: Delete the so under the x86 package

Unlike the tenth, the x86 bag is needed for the x86 model, and can be streamlined if the product doesn't work. Recommended that the actual work is configured to keep only armable, armable-x86 under the so file, is considered a compromise solution.

12th: Using the Resource compression packaging tool

Resource Compression packaging tool through the short resource name, the use of 7zip to the extreme compression of the app to reduce the target of the app, the effect is very good, highly recommended. It is recommended to turn on 7zip, note the white list configuration, otherwise it will cause some resources can not be found, roughly configured as follows,

  

13th: Compiling with provided

For some libraries are dynamically loaded as needed, it may not be necessary in some versions, but the code is not easy to remove otherwise it will compile. The use of provided can guarantee code compilation, but the actual packaging does not refer to this third-party library, achieving the goal of controlling the size of the app. But at the same time it is necessary for developers to decide not to refer to the third-party library when they do not implement the relevant code, to avoid the app crashes.

14th: Using the shape background

Especially in the current of flattening, a lot of solid color gradient rounded pictures can be achieved with shape, the code is flexible and controllable, eliminating a lot of background images.

15th: Using the coloring scheme

I believe your project also has a lot of selector files, there are many similar pictures just different colors, through the coloring scheme we can greatly reduce such a workload, reduce such files.

16th: Online Library of Materials

If your app supports libraries (such as chat emoticons), consider loading patterns online because the library has a large volume. This step requires developers to implement online loading, on the one hand to increase the complexity of the code, on the one hand to improve the app's traffic consumption, recommended as a discretionary choice.

17th: Avoid repeating the library

Avoid repeating the library seems to be taken for granted, but the secret is always deep, be aware of the third-party library you refer to which third-party library, it is easy to have a duplicate library, such as the use of two images loaded library: Glide and Picasso. Try to avoid duplicating the size of the library and reducing the size of the app by looking at the Exploded-aar directory and external libraries or decompile the generated apk.

18th: Use a smaller library

The same features of the library are different in size, or even a large disparity. If there is no particular need for a library and the size of the app is strict, compare the size of these same features third-party libraries, choosing a smaller library will reduce the size of the app.

19th: Support Plug-in

Over the past year, plug-in technology has sprung up, and these technologies support dynamic loading code and dynamic loading resources, separating part of the app, which is useful for large-scale projects, and greatly decomposes the size of the app. Because plug-in technology needs a certain degree of technical assurance and service-side system support, there is a certain risk, if not necessary (such as some small projects, there is no expansion of the business) is not necessary, the recommended choice.

20th: Streamline Functional business

This depends entirely on the business requirements. It is entirely possible to cut off some useless features from statistical analysis, or even simply remove some of the fancy features out of a light chat version, the speed version is not impossible.

21st: Repeat article 1th to 20th

You can always find some clues when performing the above steps, which is good news, isn't it?

Believe that through the above steps, you will be able to put your Android app greatly thin down. Considering a certain risk, it is advisable to choose the right method for you, and I will keep track of the latest slimming techniques and update them in a timely manner.

More exciting content can also be concerned about (huaqing vision): farsight2013

App weight loss: Lean for resources and make it better!

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.