-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildTinker.gradle
129 lines (115 loc) · 4.6 KB
/
buildTinker.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
//指定 代码工程 生成apk文件的存放位置
def bakPath = file("${buildDir}/bakApk/")
//参数配置
ext {
//开启Tinker
tinkerEnable = true
//旧的混淆映射位置,如果开启了混淆,则需要我们手动指定
tinkerApplyMappingPath = "${bakPath}/"
//旧的apk位置,需要我们手动指定
tinkerOldApkPath = "${bakPath}/app-release-2019-02-15-18-35-09.apk"
//旧的resource位置,需要我们手动指定
tinkerApplyResourcePath = "${bakPath}/app-release-2019-02-15-18-35-09-R.txt"
//指定加载patch文件时用到的Application类
tinkerApplication = "com.test.MyTinkerApplication"
tinkerID = "1.0"
}
def buildWithTinker() {
return ext.tinkerEnable
}
def getOldApkPath() {
return ext.tinkerOldApkPath
}
def getApplyMappingPath() {
return ext.tinkerApplyMappingPath
}
def getApplyResourceMappingPath(){
return ext.tinkerApplyResourcePath
}
def getTinkerIdValue(){
return ext.tinkerID
}
def getTinkerApplication(){
return ext.tinkerApplication
}
if (buildWithTinker()) {
apply plugin: 'com.tencent.tinker.patch'
tinkerPatch {
oldApk = getOldApkPath() //指定old apk文件路径
ignoreWarning = false //不忽略tinker警告,出现警告则中止patch文件生成
useSign = true //patch文件必须是签名后的
tinkerEnable = buildWithTinker() //指定是否启用tinker
buildConfig {
applyMapping = getApplyMappingPath() //指定old apk打包时所使用的混淆文件
applyResourceMapping = getApplyResourceMappingPath() //指定old apk的资源文件
tinkerId = getTinkerIdValue() //指定TinkerID
keepDexApply = false
}
dex {
dexMode = "jar" //jar、raw
pattern = ["classes*.dex", "assets/secondary-dex-?.jar"] //指定dex文件目录
loader = [getTinkerApplication()] //指定加载patch文件时用到的类
}
lib {
pattern = ["libs/*/*.so"] //指定so文件目录
}
res {
pattern = ["res/*", "assets/*", "resources.arsc", "AndroidManifest.xml"] //指定资源文件目录
ignoreChange = ["assets/sample_meta.txt"] //指定不受影响的资源路径
largeModSize = 100 //资源修改大小默认值
}
packageConfig {
configField("patchMessage", "fix the 1.0 version's bugs")
configField("platform", "all")
configField("patchVersion", "1.0")
// configField("TINKER_ID", "tinker_id_1.0") // //写这个为了修复一个bug,详见github issue #22
}
// sevenZip{ //会报错误
// zipArtifact = "com.tencent.mm:SevenZip:1.1.10"
// }
}
/**
* 是否配置了多渠道
*/
List<String> flavors = new ArrayList<>();
project.android.productFlavors.each { flavor ->
flavors.add(flavor.name)
}
boolean hasFlavors = flavors.size() > 0
/**
* 复制apk包和其它必须文件到指定目录
*/
android.applicationVariants.all { variant ->
/**
* task type, you want to bak
*/
def taskName = variant.name
def date = new Date().format("yyyy-MM-dd-HH-mm-ss")
tasks.all {
if ("assemble${taskName.capitalize()}".equalsIgnoreCase(it.name)) {
it.doLast {
copy {
def fileNamePrefix = "${project.name}-${variant.baseName}"
def newFileNamePrefix = hasFlavors ? "${fileNamePrefix}" : "${fileNamePrefix}-${date}"
def destPath = hasFlavors ? file("${bakPath}/${project.name}-${date}/${variant.flavorName}") : bakPath
from variant.outputs.outputFile
into destPath
rename { String fileName ->
fileName.replace("${fileNamePrefix}.apk", "${newFileNamePrefix}.apk")
}
from "${buildDir}/outputs/mapping/${variant.dirName}/mapping.txt"
into destPath
rename { String fileName ->
fileName.replace("mapping.txt", "${newFileNamePrefix}-mapping.txt")
}
from "${buildDir}/intermediates/symbols/${variant.dirName}/R.txt"
into destPath
rename { String fileName ->
fileName.replace("R.txt", "${newFileNamePrefix}-R.txt")
}
}
}
}
}
}
}