An overview of the
Apk slimming as part of the optimization, its size determines the time and memory occupied by the installation, targeted slimming can also improve the user experience, here is how I will be a 27.7M installation package to reduce weight to 17.5M, fully reduced by 37.18%.
First, optimize the picture
Images take up most of the volume, so image optimization is a priority.
I used TinyPng online compression tool, the size of the main image before compression (10.5m) :
Next, I used iSparta software to convert part of the picture into web format. After I transferred the picture out, AS reported an error, and I haven’t found a solution yet. If you know, you can leave a message to guide you, and have a look at the compressed size (2.68m) :
The effect is not very impressive ah, and the compressed image quality is also very good, fully meet the quality requirements of the application, some simple pictures in the project can also use SVG vector map;
Second, optimize useless resources
Delete unused resources from Lint: select inspect code…
Then I selected the Analytics app and hit OK:
Next we deal with unused resources:
Add dependencies to Project Gradle using wechat AndResGuard optimization resources:
/ / WeChat obfuscation tools classpath resources' com. Tencent. Mm: AndResGuard - gradle - plugin: 1.2.10 'Copy the code
Add configuration to App Gradle:
apply plugin: 'AndResGuard' andResGuard { // mappingFile = file("./resource_mapping.txt") mappingFile = null use7zip = true useSign = True // It will keep the origin path of your resources when it's true keepRoot = false Don't confuse resources whiteList = [/ / your icon "R.d rawable. The icon", / / a for fabric "R.string.com.crashlytics. *", // for google-services "R.string.google_app_id", "R.string.gcm_defaultSenderId", "R.string.default_web_client_id", "R.string.ga_trackingId", "R.string.firebase_database_url", "R.string.google_api_key", "R.string.google_crash_reporting_api_key" ] compressFilePattern = [ "*.png", "*.jpg", "*.jpeg", "*.webp", "*.gif", "Resources. Arsc"] sevenzip {an artifact = 'com. Tencent. Mm: sevenzip: 1.2.10' / / path = "/ usr/local/bin / 7 za"}}Copy the code
AndResGuard was optimized using the 7zzIP tool. The AndresGuard task appears in the gradle option on the right of the AS:
We can choose the type of APK we want to package for optimization;
Take a look at the Task flow:
The last step is to optimize the resource file. What kind of girl is it after optimization?
The path of the image becomes r/a5/… A;
Installation package size before optimization:
Optimized installation package size:
10.2 meters less, not bad.
Four,
Optimization work to this end, can also be optimized in place, need to work step by step, so it! Afternoon tea went to......Copy the code