Today we will pick up from the previous article on Android performance optimization -Apk Thin (1), and talk about optimizing RES resource files.

1. Optimization of RES resource files

As our project became more functional, more responsible, and more iterative, the resource files used in the project became more and more complex.

A. Delete unnecessary resource files

Refactor->Remove Unused Resources in Android Studio

At this time appear

This way we are tools feel these resources are useless, we need to have their own dialectical, those resources can be deleted, those resources can not be deleted, can not be deleted need to restore.

Of course, we can also check which resources are invalid first.

We select Analyze->Run Inspection by Name

Enter ununed resoures in the dialog box

This will output a document, we can use the document to delete the corresponding file.

2. Compress image files

A, design for the development of pictures, often will be very large, we can carry out on him, at present we use more is in the tinypng.com/ website compression, of course, can also be automated compression, Github has a useful project.

B. At present, we usually upload the picture to Blue Lake. The latest version of Blue Lake provides compression function, we can also use it.

3. Resource sharing

For the same resource, we must reuse it. For example, we should not upload N return button files for the same resource. For such files, we should clean them regularly.

4. Remove unused spare resources

Some of our SDK, tend to all areas, all of the language resources are packaged in, this way is right for the SDK, but we use only used in China, and only know the Chinese people use, we won’t need to do so for English adaptation, at this point we can reasonable use of resConfigs function, Use it to remove unnecessary resource files.

5. Resource compression

This is a tool library developed by wechat [(github.com/shwenzhang/…)]

For specific instructions, please refer to [Install Package minus 1M– wechat Android resource confusion packaging tool], which has detailed introduction.

conclusion

Apk size and we won the cost is presented positive correlation relations between the attaches great importance to the apk size in our daily development process is the basic work, every time can’t release, our App size increases the 1 m or more, effective control application size requires us to constantly in the process of project to improve their business logic, to improve the function of our business, For example, some simple pictures are replaced by code drawing, and designers are required to pay attention to resource reuse during design.