-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
178 lines (156 loc) · 5.01 KB
/
build.gradle
File metadata and controls
178 lines (156 loc) · 5.01 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
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
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds
*/
plugins {
id "base"
id "com.wiredforcode.spawn" version '0.8.2'
}
description = 'A gradle build for running multiple mobile emulators'
version = '0.0'
def numberOfAndroids = 3
def numberOfIPhones = 3
def startingEmulatorPort = 5574
def ports = (0..numberOfAndroids-1).collect { it * 2 + startingEmulatorPort }
task createDevices(group: "mobile") {
ext.createDevices = { ->
ports.each { port ->
println("Creating device test_$port")
exec {
commandLine 'avdmanager', 'create', 'avd', '--name', "test_$port", '--package', 'system-images;android-28;google_apis_playstore;x86', '--device', 'Nexus 5X'
standardOutput = new ByteArrayOutputStream();
}
}
}
ext.createIOSDevices = { ->
for(int deviceIndex: 1..numberOfIPhones) {
exec {
commandLine "xcrun", "simctl", "create", "iphone-$deviceIndex", "com.apple.CoreSimulator.SimDeviceType.iPhone-11", "com.apple.CoreSimulator.SimRuntime.iOS-13-2"
}
println("Created iOS device iphone-$deviceIndex")
}
}
doFirst {
createDevices()
createIOSDevices()
}
}
task spawnEmulators(group: "mobile", dependsOn: "createDevices") {
ext.startEmulators = { ->
ports.each { port ->
println("Starting emulator test_$port")
ProcessBuilder emulator = new ProcessBuilder()
emulator.command('emulator', '-port', "$port", "@test_$port")
emulator.start()
}
}
ext.waitForEmulatorsToStart = { ->
while (true) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'adb', 'devices'
standardOutput = stdout;
}
def statuses = "$stdout".split("\n").drop(1).collect { it.split()[1] }
println('waiting for all emulators to boot...')
sleep(3000)
if (statuses && statuses.every { it == 'device' }) break;
}
}
ext.startIosSimulators = { ->
for(int deviceIndex: 1..numberOfIPhones) {
exec {
commandLine "xcrun", "simctl", "boot", "iphone-$deviceIndex"
}
}
}
doFirst {
startEmulators()
startIosSimulators()
waitForEmulatorsToStart()
}
}
task launchMetroBundler(type: SpawnProcessTask, group: "mobile", dependsOn: "spawnEmulators") {
command "npm run start"
ready "Loading dependency graph, done."
}
task stopMetroBundler(type: KillProcessTask)
task launchApps(group: "mobile", dependsOn: "launchMetroBundler") {
ext.launchApps = { ->
ports.each { port ->
println("starting app on test_$port")
exec {
// maybe have to workingDir to app's directory here later
commandLine 'react-native', 'run-android', '--deviceId', "emulator-$port"
}
}
}
ext.launchAppsOnIPhones = { ->
for(int deviceIndex: 1..numberOfIPhones) {
exec {
commandLine "react-native", "run-ios", "--simulator", "iphone-$deviceIndex"
}
}
}
doLast {
launchAppsOnIPhones()
launchApps()
}
}
task start(group: "mobile", dependsOn: "launchApps") { }
task stopEmulators(group: "mobile", dependsOn: "stopMetroBundler") {
ext.stopEmulators = {
ports.each { port ->
try {
exec {
commandLine 'adb', '-s', "emulator-$port", 'emu', 'kill'
}
} catch (Exception ex) {
println ex
}
}
}
ext.stopIosEmulators = { ->
for(int deviceIndex: 1..numberOfIPhones) {
exec {
commandLine "xcrun", "simctl", "shutdown", "iphone-$deviceIndex"
}
}
}
doFirst {
stopEmulators()
stopIosEmulators()
}
}
task deleteDevices(group: "mobile", dependsOn: "stopEmulators") {
ext.deleteDevices = { ->
ports.each { port ->
try {
exec {
commandLine 'avdmanager', 'delete', 'avd', '--name', "test_$port"
}
} catch (Exception ex) {
println("Unable to delete android device: $ex")
}
}
}
ext.deleteIOSDevices = { ->
for(int deviceIndex: 1..numberOfIPhones) {
try {
exec {
commandLine "xcrun", "simctl", "delete", "iphone-$deviceIndex"
}
println("Deleted iOS device iphone-$deviceIndex")
} catch (Exception ex) {
println("Unable to delete iphone device: $ex")
}
}
}
doFirst {
deleteDevices()
deleteIOSDevices()
}
}
task stop(group: "mobile", dependsOn: "deleteDevices") { }