Skip to content

Commit

Permalink
修改task名为generateXXXJunkCode,加入dexCount插件
Browse files Browse the repository at this point in the history
  • Loading branch information
huangx committed Jun 19, 2020
1 parent f4c046e commit d82b74c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,39 @@ android.applicationVariants.all { variant ->
packageBase = "cn.hx.plugin.ui" //生成java类根包名
packageCount = 30 //生成包数量
activityCountPerPackage = 3 //每个包下生成Activity类数量
otherCountPerPackage = 10 //每个包下生成其它类的数量
methodCountPerClass = 10 //每个类下生成方法数量
resPrefix = "lite_junk_" //生成的layout、drawable、string等资源名前缀
drawableCount = 30 //生成drawable资源数量
stringCount = 30 //生成string数量
otherCountPerPackage = 50 //每个包下生成其它类的数量
methodCountPerClass = 20 //每个类下生成方法数量
resPrefix = "junk_" //生成的layout、drawable、string等资源名前缀
drawableCount = 300 //生成drawable资源数量
stringCount = 300 //生成string数量
})
break
}
}
```

### 生在文件所有目录
build/generated/source/junk
### 生成文件所有目录
build/generated/source/junk

### 使用插件[methodCount](https://github.com/KeepSafe/dexcount-gradle-plugin)对比

#### 未加垃圾代码
```
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个方法
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'android-junk-code'
apply plugin: 'com.getkeepsafe.dexcount'

android {
compileSdkVersion 29
Expand All @@ -26,17 +27,16 @@ android {

android.applicationVariants.all { variant ->
switch (variant.name) {
case "debug":
case "release":
androidJunkCode.configMap.put(variant.name, {
packageBase = "cn.hx.plugin.ui"
packageCount = 30
activityCountPerPackage = 3
otherCountPerPackage = 10
otherCountPerPackage = 50
methodCountPerClass = 20
resPrefix = "junk_"
drawableCount = 30
stringCount = 30
drawableCount = 300
stringCount = 300
})
break
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.novoda:bintray-release:0.9.2'
classpath "cn.hx.plugin:android-junk-code:1.0.1"
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:1.0.2"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ publish {
userOrg = bintray_Org
bintrayUser = bintray_User
bintrayKey = bintrayApikey
dryRun = false
dryRun = true
}

uploadArchives {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
if (junkCodeConfig) {
def dir = new File(project.buildDir, "generated/source/junk/$variantName")
String packageName = findPackageName(variant)
def generateJunkCodeTask = project.task("generateJunkCode${variantName.capitalize()}", type: AndroidJunkCodeTask) {
def generateJunkCodeTask = project.task("generate${variantName.capitalize()}JunkCode", type: AndroidJunkCodeTask) {
junkCodeConfig.delegate = config
junkCodeConfig.resolveStrategy = DELEGATE_FIRST
junkCodeConfig.call()
Expand Down

0 comments on commit d82b74c

Please sign in to comment.