zoukankan      html  css  js  c++  java
  • 再谈Android应用瘦身

    Android应用apk安装包的大小,虽然对于现在WiFi普及情况而言消耗流量已经微乎其微,但是,对于一款好的应用,对于一款负责任的应用,当然是越小越好了。

    引言:

    .应用越小,下载越快,也就意味着新用户能在最短时间内安装,体验应用,而不是看着通知栏里面的丑陋的下载进度条,盯着看几分钟(30-50M的应用很常见,网不好,下载几分钟很正常)就像这样...

     

    . 随着应用的迭代,应用必须满足人们越来越高的体验需求,应用需要更多的代码,更多的第三方库,更多的资源文件,随着设备的分辨率越来越高,资源文件也是水涨船高,越来越大,最终导致应用大小一直上升.如果解压一个应用,查看他的分布,会发现,最占大小的是这3部分,classes.dex, resources.asrc , res folder. 有时候assets folder 也包含比较大的视频音频图片文件.there are some tools that can help you....whaha

    正文:

    优化点1:Apk Splits  对资源文件做优化配置

    Density Splits

    复制代码
    android {
      ...
      splits {
        density {
          enable true
          exclude "ldpi", "tvdpi", "xxxhdpi"
          compatibleScreens 'small', 'normal', 'large', 'xlarge'
        }
      }
    复制代码
    enable: enables the density split mechanism
    exclude: By default all densities are included, you can remove some densities.
    include: indicate which densities to be included
    reset(): reset the list of densities to be included to an empty string (this allows, in conjunctions with include, to indicate which one to use rather than which ones to ignore)
    compatibleScreens: indicates a list of compatible screens. This will inject a matching <compatible-screens><screen ...> node in the manifest. This is optional.
     
    Note that this will also always generate a universal APK with all the densities.
     

    ABIs Splits

    复制代码
    android {
      ...
      splits {
        abi {
          enable true
          reset()
          include 'x86', 'armeabi-v7a', 'mips'
          universalApk true
        }
      }
    }
    复制代码
    enable: enables the ABIs split mechanism
    exclude: By default all ABIs are included, you can remove some ABIs.
    include: indicate which ABIs to be included
    reset(): reset the list of ABIs to be included to an empty string (this allows, in conjunctions with include, to indicate which one to use rather than which ones to ignore)
    universalApk: indicates whether to package a universal version (with all ABIs) or not. Default is false.

    优化点2:WEBP 另外一种谷歌推的web图片格式,小!!!

    具体用法,或者兼容低版本,都有解决方案。

    优化点3:Vector Drawables..同理WEBP....

    优化点4: 手动压缩图片,神器 imageoptim ,官网:https://imageoptim.com/mac

    https://www.novoda.com/blog/leaner-apks-with-custom-asset-minification/
    
  • 相关阅读:
    获取设备信息
    获取Mac地址
    常用正则
    几个字段相同的纪录去重留下主键最小的一条纪录
    mysql查询数据库中包含某字段(列名)的所有表
    nginx反向代理
    Eureka参数配置项详解
    html5验证自适应
    synchronized对象解析
    多线程进行数据同步
  • 原文地址:https://www.cnblogs.com/spring87/p/5663649.html
Copyright © 2011-2022 走看看