Android APK Slimming

Source: Internet
Author: User

Before packaging directly to use Eclipse or Android studio directly generated signature files, and did not care about the size of the problem, I was recently asked if I have to slim apk. There is no concern about this, and today we tried a variety of ways to reduce the project signature apk size by 1/4. This saves the user traffic.

1. apk File Analysis

APK is an Android installation package.

The apk file is in fact the zip format, but the suffix is changed to apk, we can unzip the folder directly such as the following:


Analyze the role of each content



View File/folder size mainly for assets, Classes.dex, LIB, res content to streamline.

2, assets streamlined

Files stored under Assets do not generate IDs, which can be stored in a variety of formats such as audio, graphics, HTML, and so on, streamlining the volume and streamlining the content.

(1) Audio: Mainly used in ringtones and notifications, the volume is not too large, the use of compressed audio format

(2) Picture: Reduce the image file size without reducing the image effect and ensuring the APK display effect.

A. Use Tinypng to optimize most image resources


The disadvantage of tinypng is that when you compress some pictures with a transition effect (with an alpha value), the picture is distorted. Such images can be used in the WEBP format. The image quality is guaranteed to greatly reduce the size of the picture.

B. Use WEBP image format

WEBP is a network picture format that supports lossy and lossless compression, assuming use of WebP in the App, in addition to the native support provided above Android4.0, the other version number to be able to use the official provided parsing library Webp-android-backport compiled into so used. Usually the UI provides images that are in PNG or JPG format. We can convert images from other formats to WEBP format using smart maps or isparta . Isparta can be used for batch conversions.

Smart map:



(3) HTML-related

HTML mainly involved in JS and CSS two of the content of the compression format to reduce the volume

3, Classes.dex

(1) Try to use the system provided string, ID, picture resources, etc.

(2) Optimize code structure, reduce redundant code

(3) Use shape to replace the picture. Image styles that can be implemented in code are implemented in code

(4) Use Proguard to confuse, optimize, and compress code, It has a feature specifically designed to reduce the size of the apk file called Tree-shaking. Proguard will traverse all of your code and then find the useless code. All of these unreachable (or unwanted) code will be erased before the last apk file is generated.

Proguard also renames your class properties, classes, and interfaces, and the entire code remains as lightweight as possible.

(5) Static code analysis tools. No need to perform, no need to test a sample scan the entire project, analyze the following potential problems, classify the description of the problem, the problem location , and provide reasonable changes to the proposal

4, Res

use androidunusedresources to check unused resources in the Android application, such as the following:

Place the downloaded jar below the project folder and enter it in the console:


Find resources that are not available to remove

5. Lib

On the phone generally only to support the Armabi can be used for x86, so the introduction of third-party libraries when the use of so deleted.


References:

1. Android Code optimization--Using the Android Lint tool

2, Android confusing file proguard.cfg specific explanation

3. How to slim your Android installation file (APK)

4. Give apk a slimming

5, about the apk slimming worth sharing some experience

6. Tools used

Android APK Slimming

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.