-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathbuild.gradle
249 lines (203 loc) · 7.51 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
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 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
}
println "Runtime using NDK_PATH: " + NDK_PATH
android {
compileSdkVersion 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 "21.1.6352462"
// ndkVersion "22.1.7171670"
}
defaultConfig {
minSdkVersion NS_DEFAULT_MIN_SDK_VERSION as int
targetSdkVersion NS_DEFAULT_COMPILE_SDK_VERSION as int
if (!optimized && !optimizedWithInspector) {
project.archivesBaseName = "${archivesBaseName}-regular"
} else {
if (optimized) {
project.archivesBaseName = "${archivesBaseName}-optimized"
} else if (optimizedWithInspector) {
project.archivesBaseName = "${archivesBaseName}-optimized-with-inspector"
}
}
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}"
}
}
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) {
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.whenTaskAdded { task ->
def taskName = task.getName()
// println "\t ~ [DEBUG][runtime] build.gradle whenTaskAdded taskName = ${taskName}"
if (taskName.contains("externalNativeBuildRelease")) {
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)
}
}
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()
}
}
}
}
}