forked from NativeScript/android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
165 lines (137 loc) · 5.12 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
apply plugin: 'com.android.library'
def optimized = project.hasProperty("optimized")
if (optimized) {
println "Optimized build triggered."
}
project.ext._buildToolsVersion = "27.0.1"
android {
sourceSets {
main {
def defaultSrcPath = "src/main/java";
def bindingGeneratorSourcePath = new File(project(":runtime-binding-generator").projectDir, defaultSrcPath)
// embedd runtime binding generator in runtime, while keeping it in a sperate project
java.srcDirs = [bindingGeneratorSourcePath, defaultSrcPath]
}
}
compileSdkVersion 26
buildToolsVersion project.ext._buildToolsVersion
publishNonDefault true
defaultConfig {
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
if (optimized) {
project.archivesBaseName = "${archivesBaseName}-optimized"
} else {
project.archivesBaseName = "${archivesBaseName}-regular"
}
externalNativeBuild {
cmake {
if (optimized) {
arguments.push("-DOPTIMIZED_BUILD=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 {
abiFilters 'x86', 'armeabi-v7a', "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
tasks.whenTaskAdded { task ->
def taskName = task.getName()
if (taskName.contains("externalNativeBuildRelease")) {
setRuntimeCommit.dependsOn(setPackageVersion)
task.dependsOn(setRuntimeCommit)
}
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()
}
}
}
}
}