Android 中的 R.class,减小 Apk 包大小

ThinRPlugin

项目地址: mogujie/ThinRPlugin
简介:去除 Android 中的 R.class,减小 Apk 包大小
  • Other languages: [简体中文] (README.zh-cn.md) .

ThinR plugin introduce


This tool will remove all the class in R.java except the styleable class and replace the referance into the constant value. So you can reduce the dex files number and apk size.

The plugin has been used on the mogujie app, the apk size is reduced by 1MB (the original apk size of 40MB), the number of DEX reduced by 3.

ThinR plugin principle

In the R.java of android project , except the class styleable , all the class fields are int object and will never change the value in the run-time.

So in the compile-time we mark all the fields' name and their values,then use the asm tool to scan all the class files to replace the name into the value.

HOW TO USE


Add the dependency in the build.gralde of the project

 classpath   'com.mogujie.gradle:ThinRPlugin:0.0.3'

Add the following code in the inner gradle file of the module :

 apply plugin: 'thinR'

 thinR {
     // In order not to affect the daily development of compilation speed, debug version can not delete R
   skipThinRDebug = true
 }

If you are using Proguard, please keep the R class in the confusion file.

-keepclassmembers class **.R$* {
     public static <fields>;
}
-keep class **.R {*;}
-keep class **.R$* {*;}
-keep class **.R$*
-keep class **.R

if you are using ButterKnife either, please keep the R2 class in the confusion file.

-keepclassmembers class **.R2$* {
     public static <fields>;
}
-keep class **.R2 {*;}
-keep class **.R2$* {*;}
-keep class **.R2$*
-keep class **.R2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值