-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
build.gradle
335 lines (271 loc) · 10 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
apply plugin: 'com.android.library'
def optimized = project.hasProperty("optimized")
if (optimized) {
println "Optimized build triggered."
}
def optimizedWithInspector = project.hasProperty("optimizedWithInspector")
if (optimizedWithInspector) {
println "Optimized build with inspector triggered."
}
def onlyX86 = project.hasProperty("onlyX86")
if (onlyX86) {
println "OnlyX86 build triggered."
}
def useCCache = project.hasProperty("useCCache")
if (useCCache) {
println "Use CCache build triggered."
}
def defaultNdkVersion = "23.2.8568313"
def hasNdkVersion = project.hasProperty("ndkVersion")
if (hasNdkVersion) {
println "Runtime using NDK version " + ndkVersion
}
def NDK_PATH = ""
def hasNdkDirectory = project.hasProperty("ndkDirectory")
if (!hasNdkDirectory) {
println "No ndkDirectory set, checking environment \$ANDROID_NDK..."
NDK_PATH = "$System.env.ANDROID_NDK"
if (NDK_PATH == null || NDK_PATH == "null") {
println "No ndkDirectory set, checking environment \$ANDROID_NDK_ROOT..."
NDK_PATH = "$System.env.ANDROID_NDK_ROOT"
}
if (NDK_PATH == null || NDK_PATH == "null") {
println "No ndkDirectory set, checking environment \$ANDROID_NDK_HOME..."
NDK_PATH = "$System.env.ANDROID_NDK_HOME"
}
} else {
NDK_PATH = ndkDirectory
}
if (NDK_PATH == null || NDK_PATH == "null" || NDK_PATH == "") {
if (!hasNdkVersion) {
NDK_PATH = "$System.env.ANDROID_HOME/ndk/${defaultNdkVersion}"
} else {
NDK_PATH = "$System.env.ANDROID_HOME/ndk/${ndkVersion}"
}
}
println "Runtime using NDK_PATH: " + NDK_PATH
base {
if (!optimized && !optimizedWithInspector) {
archivesName = "${base.archivesName.get()}-regular"
} else {
if (optimized) {
archivesName = "${base.archivesName.get()}-optimized"
} else if (optimizedWithInspector) {
archivesName = "${base.archivesName.get()}-optimized-with-inspector"
}
}
}
android {
namespace "com.tns.android_runtime"
compileSdk NS_DEFAULT_COMPILE_SDK_VERSION as int
buildToolsVersion = NS_DEFAULT_BUILD_TOOLS_VERSION as String
sourceSets {
main {
def defaultSrcPath = "src/main/java"
def bindingGeneratorSourcePath = new File(project(":runtime-binding-generator").projectDir, defaultSrcPath)
// embed runtime binding generator in runtime, while keeping it in a separate project
java.srcDirs = [bindingGeneratorSourcePath, defaultSrcPath]
}
}
if (hasNdkVersion) {
ndkVersion ndkVersion
} else {
ndkVersion defaultNdkVersion
}
defaultConfig {
minSdkVersion NS_DEFAULT_MIN_SDK_VERSION as int
targetSdkVersion NS_DEFAULT_COMPILE_SDK_VERSION as int
externalNativeBuild {
cmake {
if (optimized) {
arguments.add("-DOPTIMIZED_BUILD=true")
}
//
// if (optimizedWithInspector) {
// arguments.add("-DOPTIMIZED_WITH_INSPECTOR_BUILD=true")
// }
//
// if (useCCache) {
// arguments.add("-DUSE_CCACHE=true")
// }
//
// arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static", "-DANDROID_NDK_ROOT=${NDK_PATH}"
cppFlags "-std=c++14"
arguments "-DANDROID_STL=c++_shared", "-DANDROID_NDK_ROOT=${NDK_PATH}"
}
}
ndk {
minSdkVersion NS_DEFAULT_MIN_SDK_VERSION as int
if (onlyX86) {
abiFilters 'x86'
} else {
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
// version "3.18.1"
path "CMakeLists.txt"
}
}
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile).tap {
configureEach {
options.compilerArgs << "-Xlint:all" << "-Werror"
}
}
}
}
dependencies {
// println "\t ~ [DEBUG][runtime] build.gradle - ns_default_junit_version = ${ns_default_junit_version}..."
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation "junit:junit:${ns_default_junit_version}"
testImplementation "org.mockito:mockito-core:${ns_default_mockito_core_version}"
}
tasks.configureEach { task ->
def taskName = task.getName()
// println "\t ~ [DEBUG][runtime] build.gradle whenTaskAdded taskName = ${taskName}"
if (taskName.contains("preReleaseBuild")) {
setRuntimeCommit.dependsOn(setPackageVersion)
task.dependsOn(setRuntimeCommit)
}
if (taskName.contains("bundleReleaseAar")) {
task.dependsOn("testDebugUnitTest")
}
if (taskName.contains("Strip")) {
task.finalizedBy(revertVersionFile)
}
if ((taskName == "bundleDebug") || (taskName == "bundleRelease")) {
task.finalizedBy createPackageConfigFileTask(taskName)
}
if (task =~ /configureCMake.*/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /buildCMake.*/) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("syncReleaseLibJars") || taskName.contains("syncDebugLibJars")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("mergeReleaseJniLibFolders") || taskName.contains("mergeDebugJniLibFolders")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("mergeReleaseShaders") || taskName.contains("mergeDebugShaders")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("packageReleaseAssets") || taskName.contains("packageDebugAssets")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("copyReleaseJniLibsProjectOnly") || taskName.contains("copyDebugJniLibsProjectOnly")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("copyReleaseJniLibsProjectAndLocalJars") || taskName.contains("copyDebugJniLibsProjectAndLocalJars")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("generateReleaseLintVitalModel") || taskName.contains("generateDebugLintVitalModel")) {
task.finalizedBy(":app:buildMetadata")
}
if (taskName.contains("lintVitalAnalyzeRelease") || taskName.contains("lintVitalAnalyzeDebug")) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /lintAnalyze.+AndroidTest/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /compile.+UnitTestJavaWithJavac/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /generate.+LintModel/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /process.+Manifest/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /merge.+Resources/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /verify.+Resources/) {
task.finalizedBy(":app:buildMetadata")
}
if (task =~ /test.+UnitTest/) {
task.finalizedBy(":app:buildMetadata")
}
}
task 'setPackageVersion' {
onlyIf {
project.hasProperty('packageVersion')
}
doFirst {
println "Setting runtime version: '${packageVersion}'"
def versionFile = "$projectDir/src/main/cpp/Version.h"
String contents = new File(versionFile).getText("UTF-8")
contents = contents.replaceAll(/0.0.0.0/, packageVersion)
new File(versionFile).write(contents, "UTF-8")
}
}
task 'setRuntimeCommit' {
onlyIf {
project.hasProperty('gitCommitVersion')
}
doFirst {
println "Setting runtime commit: '${gitCommitVersion}'"
def versionFile = "$projectDir/src/main/cpp/Version.h"
String contents = new File(versionFile).getText("UTF-8")
contents = contents.replaceAll(/RUNTIME_COMMIT_SHA_PLACEHOLDER/, gitCommitVersion)
new File(versionFile).write(contents, "UTF-8")
}
}
task revertVersionFile(type: Exec) {
onlyIf {
project.hasProperty('packageVersion') || project.hasProperty('gitCommitVersion')
}
doFirst {
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
def versionFileName = "$projectDir/src/main/cpp/Version.h"
def versionFilePath = new File(versionFileName).getAbsolutePath()
println "Reverting Version.h file: ${versionFilePath}"
if (isWinOs) {
commandLine "cmd", "/c", "git", "checkout", "--", versionFilePath
} else {
commandLine "git", "checkout", "--", versionFilePath
}
}
}
repositories {
mavenCentral()
}
def createPackageConfigFileTask(taskName) {
def mode = (taskName == "bundleDebug") ? "debug" : "release"
return tasks.create(name: "packageConfigFileTaskFor${mode}",) {
def sdkDir = android.getSdkDirectory().getAbsolutePath()
doFirst {
def pathToAAR = "${buildDir}/outputs/aar/${project.archivesBaseName}-${mode}.aar"
if (new File(pathToAAR).exists()) {
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
def aaptCommand = new File(sdkDir, "/build-tools/$project.ext._buildToolsVersion/aapt").getAbsolutePath()
if (isWinOs) {
aaptCommand += ".exe"
}
def removeCmdParams = new ArrayList<String>([aaptCommand, "remove", pathToAAR, "config.json"])
exec {
ignoreExitValue true
workingDir "$projectDir/src/main"
commandLine removeCmdParams.toArray()
}
def addCmdParams = new ArrayList<String>([aaptCommand, "add", pathToAAR, "config.json"])
exec {
workingDir "$projectDir/src/main"
commandLine addCmdParams.toArray()
}
}
}
}
}