-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectMR.gradle
133 lines (105 loc) · 4.39 KB
/
collectMR.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.util.regex.Pattern
/**
* Email:angcyo@126.com
* 收集
* //混淆前后类、方法、类成员等的对照
* app/build/outputs/mapping/release/mapping.txt
*
* //被移除的代码
* app/build/outputs/mapping/release/usage.txt
*
* //没有被混淆的类和成员
* app/build/outputs/mapping/release/seeds.txt
*
* app/build/intermediates/symbols/release/R.txt
* //3.6之后R文件路径
* app/build/intermediates/runtime_symbol_list/apkRelease/R.txt
* 文件
* @author angcyo* @date 2019/11/06
* Copyright (c) 2019 ShenZhen O&M Cloud Co., Ltd. All rights reserved.
*/
///**
// * 文件输出的文件夹(基于项目根目录的相对路径)
// * */
//ext.apk_output = ".apk"
afterEvaluate {
def targets = []
def output = project.hasProperty("apk_path") ? project.ext.apk_path : ".apk"
project.tasks.each {
if (it.name.startsWith("assemble")) {
targets.add(it)
}
}
targets.each {
it.doLast {
//gradle 3.6.0 之前 路径是 /apk/release
//gradle 3.6.0 之后 路径是 /apkRelease/
println "[${it.name}] 任务结束, 开始收集文件."
//找到打包任务Task
def buildFlavors = pick(it.name /*"assemblePrePretest"*/, '(?<=assemble).*')
//分割Task Flavor
def buildFlavorsSplit = split(buildFlavors, '([A-Z]{1}[a-z]+)')
def buildDir = project.buildDir.getAbsolutePath()
//println it.name //assemblePreDebug
//println buildFlavors //PreDebug
//println buildFlavorsSplit //[Pre, Debug]
//println buildDir //E:\AndroidProjects\AccTools\AccTools\build
//1 / 0
//mapping.txt文件路径
def mappingName = "mapping.txt"
def mappingPath = "${buildDir}/outputs/mapping/${buildFlavorsSplit[0]}/${buildFlavorsSplit[1]}/${mappingName}"
def mappingPath36 = "${buildDir}/outputs/mapping/${buildFlavors}/${mappingName}"
//def mappingFile = new File(mappingPath)
//mapping.txt文件路径
def usageName = "usage.txt"
def usagePath = "${buildDir}/outputs/mapping/${buildFlavorsSplit[0]}/${buildFlavorsSplit[1]}/${usageName}"
def usagePath36 = "${buildDir}/outputs/mapping/${buildFlavors}/${usageName}"
//mapping.txt文件路径
def seedsName = "seeds.txt"
def seedsPath = "${buildDir}/outputs/mapping/${buildFlavorsSplit[0]}/${buildFlavorsSplit[1]}/${seedsName}"
def seedsPath36 = "${buildDir}/outputs/mapping/${buildFlavors}/${seedsName}"
//R.txt文件路径
def rName = "R.txt"
def rPath = "${buildDir}/intermediates/symbols/${buildFlavorsSplit[0]}/${buildFlavorsSplit[1]}/${rName}"
def rPath36 = "${buildDir}/intermediates/runtime_symbol_list/${buildFlavors}/${rName}"
//def rFile = new File(rPath)
def outputPath = "${project.rootDir.absolutePath}/${output}/"
//output
println "[collectMR.gradle] 输出目录:" + outputPath
file(outputPath).mkdirs()
//不同的风味, 收集到不同的文件夹
outputPath = "${outputPath}/${buildFlavors}/"
def outputPathFile = file(outputPath)
outputPathFile.mkdirs()
copyFile(mappingPath, outputPath + mappingName)
copyFile(mappingPath36, outputPath + mappingName)
copyFile(usagePath, outputPath + usageName)
copyFile(usagePath36, outputPath + usageName)
copyFile(seedsPath, outputPath + seedsName)
copyFile(seedsPath36, outputPath + seedsName)
copyFile(rPath, outputPath + rName)
copyFile(rPath36, outputPath + rName)
//删除空文件夹
if (outputPathFile.list().length <= 0) {
outputPathFile.deleteDir()
}
println "[collectMR.gradle] 收集文件结束."
}
}
}
static def pick(String source, String regex) {
def matcher = Pattern.compile(regex).matcher(source)
if (matcher.find()) {
return matcher.group()
} else {
return ""
}
}
static def split(String source, String regex) {
def matcher = Pattern.compile(regex).matcher(source)
def array = []
while (matcher.find()) {
array += matcher.group()
}
return array
}