此插件用于做马甲包时,减小马甲包与主包的代码相似度,避免被OPPO、VIVO等应用市场识别为马甲包。
根目录的build.gradle中:
buildscript {
dependencies {
classpath "cn.hx.plugin:android-junk-code:1.0.5"
}
}
app目录的build.gradle模块中:
apply plugin: 'com.android.application'
apply plugin: 'android-junk-code'
android {
//xxx
}
android.applicationVariants.all { variant ->
switch (variant.name) {//变体名称,如果没有设置productFlavors就是buildType名称,如果有设置productFlavors就是flavor+buildType,例如(freeRelease、proRelease)
case "release":
androidJunkCode.configMap.put(variant.name, {
packageBase = "cn.hx.plugin.ui" //生成java类根包名
packageCount = 30 //生成包数量
activityCountPerPackage = 3 //每个包下生成Activity类数量
excludeActivityJavaFile = false //是否排除生成Activity的Java文件,默认false(layout和写入AndroidManifest.xml还会执行),主要用于处理类似神策全埋点编译过慢问题
otherCountPerPackage = 50 //每个包下生成其它类的数量
methodCountPerClass = 20 //每个类下生成方法数量
resPrefix = "junk_" //生成的layout、drawable、string等资源名前缀
drawableCount = 300 //生成drawable资源数量
stringCount = 300 //生成string数量
})
break
}
}
build/generated/source/junk
使用插件methodCount对比
Total methods in app-debug.apk: 26162 (39.92% used)
Total fields in app-debug.apk: 12771 (19.49% used)
Total classes in app-debug.apk: 2897 (4.42% used)
Methods remaining in app-debug.apk: 39373
Fields remaining in app-debug.apk: 52764
Classes remaining in app-debug.apk: 62638
Total methods in app-release-unsigned.apk: 59733 (91.15% used)
Total fields in app-release-unsigned.apk: 13462 (20.54% used)
Total classes in app-release-unsigned.apk: 4488 (6.85% used)
Methods remaining in app-release-unsigned.apk: 5802
Fields remaining in app-release-unsigned.apk: 52073
Classes remaining in app-release-unsigned.apk: 61047
增加了1591个类33571个方法