-
Notifications
You must be signed in to change notification settings - Fork 81
/
plug.gradle
213 lines (180 loc) · 7.41 KB
/
plug.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import org.apache.tools.ant.taskdefs.condition.Os
// add dependencies project
if (project.ext.has("complieProject")) {
def complieProjects = project.ext.get("complieProject")
if (complieProjects != null) {
for (String compileProjectName : complieProjects) {
def projectPath = project.projectDir.absolutePath
projectPath = projectPath.substring(projectPath.indexOf("plugProject"))
def splitStr = File.separator;
if(Os.isFamily(Os.FAMILY_WINDOWS)){
splitStr = "\\\\";
}
def projectPathArray = projectPath.split(splitStr)
if (projectPathArray.length >= 2) {
projectPath=""
for(int i=0;i<projectPathArray.length-1;i++){
projectPath += ":" + projectPathArray[i]
}
projectPath += compileProjectName
println("compileProject "+projectPath)
project.dependencies {
compile project(projectPath)
}
}
}
}
}
project.android {
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
checkReleaseBuilds false
disable 'InvalidPackage'
abortOnError false
}
aaptOptions {
useNewCruncher false
cruncherEnabled false
}
}
def pluglibPath = "${project.rootProject.projectDir}${File.separator}libs_ex"
project.dependencies {
compile project(':common_ui')
provided files(pluglibPath + File.separator + "pluglib.jar")
provided files(pluglibPath + File.separator + "libammsdk.jar")
provided files(pluglibPath + File.separator + "support-v4-23.1.1.jar")
provided files(pluglibPath + File.separator + "internal_impl-23.1.1.jar")
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-v7'
all*.exclude group: 'com.android.support', module: 'support-v13'
}
project.evaluationDependsOn(":pluglib")
project.android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def defaultOutputFile = output.outputFile
if (defaultOutputFile != null && defaultOutputFile.name.endsWith('.apk')) {
output.outputFileName = project.name + "-" + android.defaultConfig.versionCode + "-" + android.defaultConfig.versionName + "-" + variant.buildType.name + ".apk"
}
}
}
project.afterEvaluate {
def beforePrapareTaskName = "preBuild"
def beforePrapareTask = project.tasks.findByName(beforePrapareTaskName)
def compliePluglibTaskName = "makeJar"
def compliePluglibTask = project.rootProject.project(":pluglib").tasks.findByName(compliePluglibTaskName)
if (compliePluglibTask != null) {
compliePluglibTask.doLast({
copy {
from "${project.rootProject.projectDir}${File.separator}pluglib${File.separator}build${File.separator}libs${File.separator}"
into pluglibPath
include('*.jar')
}
})
beforePrapareTask.dependsOn compliePluglibTask
} else {
println "not found task:" + compliePluglibTaskName
}
//////
project.android.applicationVariants.each { variant ->
def assembleTaskName = "assemble${variant.name.capitalize()}"
def assembleTask = project.tasks.findByName(assembleTaskName)
if (assembleTask != null) {
assembleTask.doLast({
installPlugin(project, variant);
});
def insatallTaskName = "install${variant.name.capitalize()}"
project.task(insatallTaskName, overwrite: true) << {
// installPlugin(project, variant);
}
def installTask = project.tasks.findByName(insatallTaskName)
installTask.dependsOn assembleTaskName
if (variant.name.capitalize().equals("Release")) {
insatallTaskName = "install"
project.task(insatallTaskName, overwrite: true) << {
// installPlugin(project, variant);
}
installTask = project.tasks.findByName(insatallTaskName)
installTask.dependsOn assembleTaskName
}
///
insatallTaskName = "install${project.name.capitalize()}${variant.name.capitalize()}"
project.task(insatallTaskName, overwrite: true) << {
// installPlugin(project, variant);
}
installTask = project.tasks.findByName(insatallTaskName)
installTask.dependsOn assembleTaskName
if (variant.name.capitalize().equals("Release")) {
insatallTaskName = "install" + project.name.capitalize()
project.task(insatallTaskName, overwrite: true) << {
// installPlugin(project, variant);
}
installTask = project.tasks.findByName(insatallTaskName)
installTask.dependsOn assembleTaskName
}
}
}
}
void installPlugin(def project, def variant) {
variant.outputs.each { output ->
def defaultOutputFile = output.outputFile
if (defaultOutputFile != null && defaultOutputFile.name.endsWith('.apk')) {
println("install plug:" + defaultOutputFile)
Properties properties = new Properties()
File localProps = project.rootProject.file("local.properties")
def sdkDir
if (localProps.exists()) {
properties.load(localProps.newDataInputStream())
sdkDir = properties.getProperty("sdk.dir")
} else {
sdkDir = System.getenv("ANDROID_HOME")
}
if (sdkDir) {
int plugid = (int) (java.lang.Math.random() * 10)
if (plugid == 0) {
plugid = 9
}
def adbcmd = "${sdkDir}/platform-tools/adb"
if(Os.isFamily(Os.FAMILY_WINDOWS)){
adbcmd = "${sdkDir}\\platform-tools\\adb"
}
def stdout = new ByteArrayOutputStream()
project.exec {
commandLine adbcmd,
"shell",
"am force-stop com.xiaomi.smarthome"
}
project.exec {
commandLine adbcmd,
"shell",
"am start com.xiaomi.smarthome/.SmartHomeMainActivity"
}
sleep(3000);
project.exec {
commandLine adbcmd,
"push",
defaultOutputFile,
"/sdcard/SmartHome/plugin/debug/${plugid}.mpk"
standardOutput = stdout
}
def error = stdout.toString().trim()
if (error) {
println "install push error:" + error
}
sleep(5000);
project.exec {
commandLine adbcmd,
"shell",
"am broadcast -a com.xiaomi.smarthome.action.OPEN_API -n com.xiaomi.smarthome/.framework.openapi.OpenApiReceiver --es type plugin_debug --es sub_type debug_package"
}
} else {
println "not found android sdk dir"
}
}
}
}