| 
                         在 app 目录下,创建 and_res_guard.gradle 文件 
- apply plugin: 'AndResGuard' 
 - andResGuard { 
 -  mappingFile = null 
 -  use7zip = true 
 -  useSign = true 
 -  keepRoot = false 
 -  compressFilePattern = [ 
 -  "*.png", 
 -  "*.jpg", 
 -  "*.jpeg", 
 -  "*.gif", 
 -  "resources.arsc" 
 -  ] 
 -  whiteList = [ 
 -  // your icon 
 -  "R.drawable.icon", 
 -  // for fabric 
 -  "R.string.com.crashlytics.*", 
 -  // for umeng update 
 -  "R.string.tb_*", 
 -  "R.layout.tb_*", 
 -  "R.drawable.tb_*", 
 -  "R.drawable.u1*", 
 -  "R.drawable.u2*", 
 -  "R.color.tb_*", 
 -  // umeng share for sina 
 -  "R.drawable.sina*", 
 -  // for google-services.json 
 -  "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", 
 -  //友盟 
 -  "R.string.umeng*", 
 -  "R.string.UM*", 
 -  "R.layout.umeng*", 
 -  "R.drawable.umeng*", 
 -  "R.id.umeng*", 
 -  "R.anim.umeng*", 
 -  "R.color.umeng*", 
 -  "R.style.*UM*", 
 -  "R.style.umeng*", 
 -  //融云 
 -  "R.drawable.u*", 
 -  "R.drawable.rc_*", 
 -  "R.string.rc_*", 
 -  "R.layout.rc_*", 
 -  "R.color.rc_*", 
 -  "R.id.rc_*", 
 -  "R.style.rc_*", 
 -  "R.dimen.rc_*", 
 -  "R.array.rc_*" 
 -  ] 
 -  sevenzip { 
 -  artifact = 'com.tencent.mm:SevenZip:1.2.10' 
 -  } 
 - } 
 
  
在 app 模块下的 build.gradle 文件添加 
- apply from: 'and_res_guard.gradle' 
 
  
打包完之后效果图 
  
  
资源压缩了大概 1M
总结 
项目体积越大,资源越多,效果就越明显。 
使用 Link 删除资源的话,一定要谨慎,提前做好备份。 
咱们这里因为项目本身只有 22 M 多,最后优化了 4.5 M 下去。也还是很不容易的。                         (编辑:滁州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |