-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugment.gradle
More file actions
94 lines (86 loc) · 2.28 KB
/
augment.gradle
File metadata and controls
94 lines (86 loc) · 2.28 KB
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
/**
* 生成的插件文件名
*/
def plugnExistName = "user.jar"
/**
* adb push更新时的插件名
*/
def plugnPushName = "user.jar"
/**
* 宿主工程包名
*/
def packageName = "com.aike.xky"
/**
* 启动页
*/
def launcherActivity = "com.aike.xky.splash.AikeSplashActivity"
tasks.all{
task->
if (task.name.startsWith("assemble") && !task.name.contains("Release")){
doLast{
pushPlugin.execute()
}
}
}
task pushPlugin{
group 'augment'
doFirst{
def apkExistPath = transferPath(new File(project.getBuildDir().absolutePath+"/outputs/apk", plugnExistName).absolutePath)
if(isWindows()){
apkExistPath = new File(project.getBuildDir().absolutePath+"/outputs/apk", plugnExistName).absolutePath
}
def command = "adb shell mkdir sdcard/aikeplugins | adb push -p $apkExistPath sdcard/aikeplugins/$plugnPushName | adb shell am force-stop $packageName"
exec {
try{
if(isWindows()){
commandLine 'cmd',"/c","$command"
}else{
executable 'bash'
args "-c", "$command"
}
}catch(Exception e){
println e.message
println("=====================push plugin failed with exception.=========================")
}
}
println("=====================push plugin successfull.=========================")
}
doLast{
restart.execute()
}
}
def transferPath(String path){
def file = new File(path);
if (file.separator == "\\") {
path = path.replace("\\", "/")
path = path.replace(":", "")
path = "/" + path
}
return path;
}
task restart{
group 'augment'
doLast{
def command = "adb shell am start -n $packageName/$launcherActivity"
if(isWindows()){
command = "adb shell am start -n $packageName/$launcherActivity | taskkill /f /im java.exe"
}
exec {
try {
if(isWindows()){
commandLine 'cmd',"/c","$command"
}else{
executable 'bash'
args "-c", "$command"
}
} catch (Exception e) {
println e.message
println("=====================restart failed with exception.=========================")
}
}
println("=====================restart successfull.=========================")
}
}
def isWindows() {
return System.properties['os.name'].contains('Windows')
}