Objective
Before I briefly introduced the problem of the SVG picture slimming, in the company, the problem of thin body is I put forward, so this pot I back. The company project is 32.6M, I give myself the requirement is less than 20M. It took me one weeks to lose weight last week, and I was blinded by why I spent a week, mostly on the SVG adaptation. And then found to change a lot of code, think about it, and changed another way of slimming.
Many people are because of this title, how can, 32.6M incredibly can become 13.6M. Let me take a slow path.
APK Structure Introduction
Classes.dex
Classes.dex is a Java bytecode file generated after the Java source code is compiled. However, because the Dalvik virtual machine used by Android is incompatible with the standard Java Virtual machine, the Dex file is different from the class file, whether it is a file structure or opcode. None of the common Java Anti-compilation tools currently work with Dex files. The Android emulator provides an anti-compilation tool for the Dex file, Dexdump. Use to start the Android emulator first, put the Dex file you want to view in an emulator uploaded by ADB push, and then log in with the ADB shell to find the Dex file to view and execute Dexdump xxx.dex. Also, it was introduced that Dedexer is the only open source tool that can be found on the web that compiles the Dex file, and it needs to compile its own source code.
Clases2.dex
Above is the compilation of your Java file, which is the compilation of the jar file you imported.
Resources.arsc
Compiled binary resource file
Androidmainfest.xml
This file must be defined and included in each app, which describes the name, version, permissions, referenced library files, and so on, to upload the apk to Google Market, and to configure the XML.
Assets
Assets directory can hold some configuration files (such as WebView local resources, image resources, etc.), the contents of these files can be obtained through the relevant API during the process of running the program.
Lib
The subdirectory under the Lib directory Armeabi contains some so files. This place to say a few more words, all is in the development process to grope out. Eclipse will pack so files according to the naming rules (lib**.so) of the file name, starting and ending with "Lib" and ". So", otherwise it will not be packaged in the APK file. Other non-Eclipse development environments have not been tested. If you are using the SDK and the NDK development, this part is very important, you can even by renaming some files that are not so files through the name of the APK, specifically what to do it depends on what you want to do!
Meta-inf
The Meta-inf directory contains signature information that is used to ensure the integrity of the APK package and the security of the system.
Res directory
Here are some resource files that we store XML drawable string color and so on.
32.6m--13.6m
First of all, I first declare, or I am afraid will be beaten, the current 13.6M is still in the test, because the model problem, the current can not be tested. The size of the stable package is now in 19.8m--20.4m.
Confusing and removing useless resources
The Gradle uses minifyenabled for proguard confusing configuration, which greatly reduces the app size
Delete useless picture resources
Our company project has been 2 years now. It is conceivable that there is too much redundancy in the code. A version update can cause a lot of resources to be used, and then still exist in the package. This matter I was handed over to the eldest brother to do, after all, the project he most familiar. So far, almost 100 pictures have been deleted. Because I did a picture adaptation. So the deletion of the image resources is almost in the form of 400. Such Our app package has changed from 32.6M to 26.8M. Remember when you just packed the test, the Test manager came up with a sentence. You this bag is not right, how is missing 6, 7M. And then it's normal to say that I'm going to be around 20M at this end. Test Manager: What? In a thin 20M. So exaggerated. I: ... well, no, it's off the topic.
Delete Useless resource resources
This is certainly not the same as the above. My main point here is XML. First, we need to click Analyze-->run Inspection by Name ...
Continue input: unused resource
Just click OK, then wait:
It seems that the company's project can also be less a 300k~. You can compare your projects by deleting them.
Pictures of Slimming Panda Dafa
I've said it before. The amount of code used in SVG adaptation is too large. So I switched to the panda slimming, which is tinypng. Official website: https://tinypng.com. Below I introduce to you from the official website tinypng:
What role does Tinypng have?
Tinypng uses intelligent lossy compression technology to reduce the file size of PNG files. By selectively reducing the number of colors in an image, fewer bytes are needed to store the data. The effect is almost invisible, but it makes a big difference in file size!
Why use Tinypng?
PNG is useful because it is the only widely supported format that can store partially transparent images. The format uses compression, but the file may still be large. Use Tinypng to narrow down the images for your apps and websites. It will use less bandwidth and faster loading.
How does it work?
When you upload a PNG (Portable Network Graphics) file, similar colors in the image are merged. This technique is called "quantification". By reducing the number of colors, a 24-bit PNG file can be converted to a smaller 8-bit indexed color image. All unnecessary metadata is also deleted. Result: A better PNG file 100% supports transparency. Have your cake and eat it!
Does IT support everywhere?
The files generated by Tinypng are displayed perfectly on all modern browsers, including mobile devices. Still need to support Internet Explorer 6? It usually ignores PNG transparency and displays a solid background color. The background of using tinypng becomes transparent. There is no workaround for binary transparency!
Why did you create tinypng?
We often use PNG images, but we are disappointed with the loading time. We create tinypng in our mission to make our own website faster and more fun to use with the best compression. In 2014, we added smart compression for JPEG images, and in 2016 we added support for animated PNG.
How to use
We see the introduction of the official website, upload your jpg or PNG here at a maximum of 20, each maximum 5MB. Next we'll take a test:
Change from 1.4M to 570k. Shrank by 60%. It is conceivable that the panda is powerful. If you want to upload all at once, this TM is embarrassing. $25 a year. You can let your UI give you the picture when you use tinypng compression in the hair. But some companies will give you a design draft. Then you have to do it yourself.
Panda Dafa vs svg Dafa
I compared the compression of Pandas and SVG, the former app ' size is at 20.4M, the latter is at 19.8M. Below you compare:
19.8m--13.6m
I also said earlier, this is still testing the model. So stability is not guaranteed. Let's talk about how to do it. We use the Baidu Map SDK for our company projects. All are used in so library.
Of course, my side is only part. Below I have found some introduction about these so libraries:
What exactly is MIPS, Armeabi, ARMEABI-V7A, and x86
Mips:mips is one of the most popular RISC processors in the world. MIPS means "No internal interlocking microprocessor" (microprocessor without interlocked
Piped stages),
Its mechanism is to use the software approach to avoid data-related problems in the pipeline.
Armeabi: The default option is created to be based on the
arm* the V5TE device as the target library. Floating-point operations with this goal use software floating-point arithmetic. Use this ABI (binary interface)
The binary code you create will run on all arm* devices. So Armeabi is very versatile. But the speed is slow
ARMEABI-V7A: Create support based on
arm* A library of V7 devices and will use the hardware FPU instructions. The armeabi-v7a is an arm v7 CPU with floating-point arithmetic or advanced expansion capabilities.
x86: Support for hardware-based floating-point arithmetic
IA-32 instruction set. x86 is compatible with the Armeabi platform, whether it is armeabi-v7a or Armeabi, but also the performance of the loss,
It is also necessary to point out that the packaged x86 so will always be smaller than the size of the Armeabi platform.
Summary
If the project contains only Armeabi, it can be run on all Android devices;
If the project contains only armeabi-v7a, it can be run in addition to the Armeabi architecture;
If the project contains only x86, then the Armeabi architecture and armeabi-v7a Android devices will not work, and if both Armeabi, armeabi-v7a and x86 are included,
All devices can be run, the program at run time to load different platforms corresponding to so, this is a more perfect solution, but also cause the package to become larger.
Therefore, this still needs to be based on the user's model to judge, visual inspection of my side is still in the test, if no problem. The size is basically around 13.6M.
Summarize
We need to be aware of the structure of the app when we want to lose weight, just as I did when I first did it, but it was a blind-to-face situation for all sorts of problems. So, we need to understand what each file under the APK package is, what it does, and whether it works. If you do it with your heart, you will be able to solve it. Just as I had given myself a goal of less than 20M. Although now and 20M is similar. But if the tests over there can pass. That's 13.6M instead of 20M. I hope my method will help you. Welcome to discuss ~ ~ ~
Android APK Slimming Comprehensive Summary-how to from 32.6M to 13.6M