-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathbuild.gradle
209 lines (174 loc) · 6.37 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
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."
}
project.ext._buildToolsVersion = "28.0.3"
android {
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]
}
}
compileSdkVersion 28
buildToolsVersion project.ext._buildToolsVersion
defaultConfig {
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
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")
}
//https://developer.android.com/ndk/guides/cmake.html
//TODO: plamen5kov: figure out why can't ANDROID_TOOLCHAIN and ANDROID_STL be set in CMakeLists.txt
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static", "-DANDROID_NDK_ROOT=${android.ndkDirectory}"
}
}
ndk {
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 {
path "CMakeLists.txt"
}
}
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Werror"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
}
tasks.whenTaskAdded { task ->
def taskName = task.getName()
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
}
}
}
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()
}
}
}
}
}