-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
177 lines (154 loc) · 5.8 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
import java.util.regex.Pattern
allprojects {
ext {
airshipProperties = new Properties()
airshipProperties.load(new FileInputStream("airship.properties"))
}
}
configurations {
plugin
}
repositories {
google()
ivy {
url 'https://github.com'
patternLayout {
artifact '[organisation]/[module]/archive/[revision].[ext]'
}
metadataSources {
artifact()
}
}
}
dependencies {
plugin "googlesamples:unity-jar-resolver:${airshipProperties.playServicesResolver}@zip"
}
task preparePlugin(dependsOn: 'unity-plugin:assembleRelease') {
doFirst {
delete {
"$buildDir"
}
}
doLast {
// Copy Android plugin
copy {
from file("unity-plugin/build/outputs/aar/unity-plugin-release.aar")
into file("$buildDir/unity-plugin/Assets/Plugins/Android/")
rename("unity-plugin-release.aar", "airship-unity-plugin.aar")
}
// Copy unity jar resolver
copy {
def zipPath = project.configurations.plugin.find {it.name.startsWith("unity-jar-resolver") }
def zipFile = file(zipPath)
def outputDir = file("${buildDir}/packages")
from zipTree(zipFile)
into outputDir
include "*/*.unitypackage"
}
// Copy the Assets, exclude PluginInfo.cs and UADependencies.xml so we can copy and replace the version placeholder
copy {
from file("Assets")
into file("$buildDir/unity-plugin/Assets/")
exclude "UrbanAirship/PluginInfo.cs"
exclude "UrbanAirship/Editor/UADependencies.xml"
// exclude unit tests
exclude "UrbanAirship/Tests"
exclude "UrbanAirship/Platforms/AssemblyInfo.cs"
exclude "UrbanAirship/Platforms/UrbanAirship.asmdef"
}
// Copy PluginInfo.cs and replace the version placeholders
copy {
from file("Assets")
into file("$buildDir/unity-plugin/Assets/")
include "UrbanAirship/PluginInfo.cs"
filter { String line -> line.replaceAll(Pattern.quote("__PLUGIN_VERSION__"), airshipProperties.version) }
filter { String line -> line.replaceAll(Pattern.quote("__ANDROID_AIRSHIP_VERSION__"), airshipProperties.androidAirshipVersion) }
filter { String line -> line.replaceAll(Pattern.quote("__IOS_AIRSHIP_VERSION__"), airshipProperties.iosAirshipVersion) }
}
// Copy UADependencies.xml and replace the version placeholders
copy {
from file("Assets")
into file("$buildDir/unity-plugin/Assets/")
include "UrbanAirship/Editor/UADependencies.xml"
filter { String line -> line.replaceAll(Pattern.quote("__PLUGIN_VERSION__"), airshipProperties.version) }
filter { String line -> line.replaceAll(Pattern.quote("__ANDROID_AIRSHIP_VERSION__"), airshipProperties.androidAirshipVersion) }
filter { String line -> line.replaceAll(Pattern.quote("__ANDROID_ANNOTATIONS_VERSION__"), airshipProperties.androidxAnnotationVersion) }
filter { String line -> line.replaceAll(Pattern.quote("__IOS_AIRSHIP_VERSION__"), airshipProperties.iosAirshipVersion) }
}
}
}
task build(dependsOn: 'preparePlugin') {
doLast {
// Add each package
def packages = fileTree("${buildDir}/packages") {
include '**/*.unitypackage'
}
packages.each { file ->
def addPackageOptions = [
"-g.building",
"-gvh_disable",
"-batchmode",
"-nographics",
"-createProject", "$buildDir/unity-plugin",
"-logFile", "$buildDir/package-${file.name}.log",
"-importPackage", "$file",
"-quit"
]
exec {
workingDir "$buildDir/unity-plugin"
executable "${getUnityExePath()}"
args addPackageOptions
}
}
// Export the plugin
def exportPackageOptions = [
"-g.building",
"-batchmode",
"-nographics",
"-gvh_disable",
"-projectPath", "$buildDir/unity-plugin",
"-logFile", "$buildDir/package.log",
"-exportPackage",
"Assets/PlayServicesResolver",
"Assets/ExternalDependencyManager",
"Assets/UrbanAirship",
"Assets/Plugins/iOS",
"Assets/Plugins/Android/urbanairship-resources.androidlib",
"Assets/Plugins/Android",
"Assets/Scripts",
file("build/urbanairship-${airshipProperties.version}.unitypackage").absolutePath,
"-quit"
]
exec {
workingDir "$buildDir/unity-plugin"
executable "${getUnityExePath()}"
args exportPackageOptions
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
task getUnityVersion() {
doLast {
println airshipProperties.unityVersion
}
}
task getPluginVersion() {
doLast {
println airshipProperties.version
}
}
def getUnityExePath() {
def unityExe = System.getProperty("UNITY_EXE")
if (unityExe == null || unityExe.isEmpty()) {
unityExe = System.getenv("UNITY_EXE")
}
if (unityExe == null || unityExe.isEmpty() || !file(unityExe).exists()) {
unityExe = "/Applications/Unity/Hub/Editor/$airshipProperties.unityVersion/Unity.app/Contents/MacOS/Unity"
}
if (unityExe == null || unityExe.isEmpty() || !file(unityExe).exists()) {
throw new GradleException('Unable to find Unity executable.')
}
return unityExe
}