This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
build.gradle
211 lines (196 loc) · 6.47 KB
/
build.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
/*
* Gradle file to build the Google Play Instant Plugin for Unity.
* See https://docs.unity3d.com/Manual/CommandLineArguments.html
*/
buildscript {
repositories {
google()
jcenter()
}
}
/*
* Project level variables.
*/
project.ext {
// The Unity Editor executable path can be passed in from the command line:
// -PunityExe=/path/to/unity/editor
// If the path is not provided, a default path will be tried based on the OS.
if (!project.hasProperty('unityExe')) {
def osName = System.getProperty('os.name').toLowerCase();
if (osName.contains('mac os x')) {
unityExe = '/Applications/Unity/Unity.app/Contents/MacOS/Unity'
} else if (osName.contains('windows')) {
unityExe = 'C:\\Program Files\\Unity\\Editor\\Unity.exe'
} else if (osName.contains('linux')) {
unityExe = '/opt/Unity/Editor/Unity'
} else {
throw new GradleException("Unsupported OS: $osName")
}
}
if (!file(unityExe).exists()) {
throw new GradleException("Unity Editor not found: $unityExe")
}
// If the git project is located directly under the Assets folder, then we move up two
// directories for the root of the build path. This avoids conflicts in a working Unity
// project where we'd copy files and get duplicate class name build errors.
def rootPath = file('.')
def assetsPath = rootPath.getParentFile()
if (assetsPath.getName() == 'Assets') {
rootPath = assetsPath.getParentFile()
}
playInstantBuildPath = "${rootPath}/play-instant-build"
playInstantArtifactsPath = "${playInstantBuildPath}/artifacts"
file(playInstantArtifactsPath).mkdirs();
}
def copyCommonFiles(def projectPath) {
description 'Copies project files needed by all tasks into the specified build staging location'
copy {
from('GooglePlayInstant') {
exclude 'Samples', 'Samples.meta', 'Tests', 'Tests.meta'
}
into "${projectPath}/Assets/GooglePlayInstant"
}
copy {
from 'GooglePlayInstant.meta'
into "${projectPath}/Assets"
}
}
def buildApp(def executeMethod, def projectPath) {
description 'Calls Unity on the command line to build the specified app'
def projectName = file(projectPath).getName()
def logFile = "${playInstantArtifactsPath}/${projectName}.log"
// Note: this a prefix and the Editor build script should add a suffix, e.g. '.apk'.
def outputFile = "${playInstantArtifactsPath}/${projectName}"
println "Building app: ${projectName}"
def argv = [
'-batchmode',
'-quit',
'-nographics',
'-buildTarget',
'Android',
'-executeMethod',
executeMethod,
'-projectPath',
projectPath,
'-logFile',
logFile,
'-outputFile',
outputFile
]
exec {
executable unityExe
args argv
}
// The symbols files created during IL2CPP builds are each ~400MB.
// Delete these files so they don't get archived with each build.
delete fileTree(playInstantArtifactsPath) {
include '*.symbols.zip'
}
}
def exportUnityPackage(def pluginName, def projectPath) {
def utilsFilePath = "${projectPath}/Assets/GooglePlayInstant/GooglePlayInstantUtils.cs"
def utilsFileContents = new File(utilsFilePath).text
def pluginVersion = (utilsFileContents =~ /PluginVersion = "(.+)";/)[0][1]
def outputFile = "${playInstantArtifactsPath}/${pluginName}-${pluginVersion}.unitypackage"
def logFile = "${playInstantArtifactsPath}/${pluginName}.log"
def argv = [
'-batchmode',
'-quit',
'-nographics',
'-projectPath',
projectPath,
'-logFile',
logFile,
'-exportPackage',
'Assets/GooglePlayInstant'
]
if (file("${projectPath}/Assets/Plugins/Android").isDirectory()) {
argv << 'Assets/Plugins/Android'
}
argv << outputFile
exec {
executable unityExe
args argv
}
}
task exportPlugin {
description 'Creates and exports the plugin as a .unitypackage'
def projectPath = "${playInstantBuildPath}/plugin"
doFirst {
copyCommonFiles(projectPath)
}
doLast {
exportUnityPackage('play-instant-plugin', projectPath)
}
}
task buildInstantTestApp {
description 'Builds the Google Play Instant test app'
def buildFunction = 'GooglePlayInstant.Samples.TestApp.Editor.TestAppBuilder.Build'
def projectPath = "${playInstantBuildPath}/testapp"
doFirst {
copyCommonFiles(projectPath)
copy {
from 'GooglePlayInstant/Samples/TestApp'
into "${projectPath}/Assets/TestApp"
}
}
doLast {
buildApp(buildFunction, projectPath)
}
}
task zipInstantTestApp(type: Zip) {
mustRunAfter 'buildInstantTestApp'
from playInstantArtifactsPath
include 'testapp.apk'
archiveName 'testapp.zip'
destinationDir file(playInstantArtifactsPath)
}
task buildSphereBlastApp {
description 'Builds the SphereBlast sample as an instant app'
def buildFunction = 'GooglePlayInstant.Samples.SphereBlast.Editor.SphereBlastBuilder.Build'
def projectPath = "${playInstantBuildPath}/sphereblast"
doFirst {
copyCommonFiles(projectPath)
copy {
from 'GooglePlayInstant/Samples/SphereBlast'
into "${projectPath}/Assets/SphereBlast"
}
}
doLast {
buildApp(buildFunction, projectPath)
}
}
task tests {
description 'Runs Editor unit tests with Unity test runner'
def projectPath = "${playInstantBuildPath}/tests"
def logFile = "${playInstantArtifactsPath}/tests.log"
def resultFile = "${playInstantArtifactsPath}/tests.xml"
doFirst {
copyCommonFiles(projectPath)
copy {
from 'GooglePlayInstant/Tests'
into "${projectPath}/Assets/GooglePlayInstant/Tests"
}
}
doLast {
def argv = [
'-batchmode',
'-projectPath',
projectPath,
'-logFile',
logFile,
'-editorTestsResultFile',
resultFile,
'-runEditorTests'
]
exec {
executable unityExe
args argv
}
}
}
task clean(type: Delete) {
description 'Removes build artifacts'
delete playInstantBuildPath
}
project.defaultTasks = ['tests', 'exportPlugin']