forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
345 lines (320 loc) · 12.7 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
336
337
338
339
340
341
342
343
344
345
import com.android.build.gradle.tasks.ExternalNativeCleanTask
import groovy.json.JsonSlurper
/**
* Titanium SDK
* Copyright TiDev, Inc. 04/07/2022-Present
* Licensed under the terms of the Apache Public License.
* Please see the LICENSE included with this distribution for details.
*/
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
// Fetch Titanium version info to be applied to generated "BuildConfig" Java class and published AAR.
// Prefer environment variables assigned via build/package scripts under "titanium_mobile/build" folder.
def tiBuildVersionString = System.env.TI_SDK_BUILD_VERSION
if (tiBuildVersionString == null) {
def packageJson = new JsonSlurper().parse(file("${projectDir}/../../package.json"))
tiBuildVersionString = packageJson.version
if (tiBuildVersionString == null) {
tiBuildVersionString = '1.0.0'
}
}
def tiBuildHashString = System.env.TI_SDK_BUILD_GIT_HASH
if (tiBuildHashString == null) {
tiBuildHashString = 'HEAD'
}
def tiBuildTimeString = System.env.TI_SDK_BUILD_TIMESTAMP
if (tiBuildTimeString == null) {
tiBuildTimeString = (new Date()).format('MM/dd/yyyy HH:mm', TimeZone.getTimeZone("UTC"))
}
def tiBuildVersionCode = 0
for (nextString in tiBuildVersionString.split('\\.')) {
def intValue = Math.max(Integer.parseInt(nextString), 0)
if (tiBuildVersionCode <= 0) {
tiBuildVersionCode = intValue
} else {
tiBuildVersionCode *= 100
tiBuildVersionCode += Math.min(intValue, 99)
}
}
android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 21
targetSdkVersion 33
versionName tiBuildVersionString
versionCode tiBuildVersionCode
buildConfigField('int', 'VERSION_CODE', tiBuildVersionCode.toString())
buildConfigField('String', 'VERSION_NAME', '"' + tiBuildVersionString + '"')
buildConfigField('String', 'TI_BUILD_HASH_STRING', '"' + tiBuildHashString + '"')
buildConfigField('String', 'TI_BUILD_TIME_STRING', '"' + tiBuildTimeString + '"')
manifestPlaceholders = project.ext.tiManifestPlaceholders
javaCompileOptions {
annotationProcessorOptions {
// Set up "kroll-apt" @Kroll annotation processor to generate C/C++ code bindings between V8/Java.
// Also have it produce a JSON file of all bindings to be used by module build system.
arguments = [
'kroll.outputJsonFilePath': "${projectDir}/../../dist/android/titanium.bindings.json".toString(),
'kroll.outputCppDirPath': "${projectDir}/../runtime/v8/generated".toString(),
'kroll.jsModuleName': 'titanium'
]
}
}
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
}
}
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
externalNativeBuild {
cmake {
version '3.10.2'
path "${projectDir}/../runtime/v8/src/native/CMakeLists.txt"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
assets.srcDirs = [
'assets',
"${projectDir}/../modules/ui/assets"
]
java.srcDirs = [
'src/java',
"${projectDir}/../modules/accelerometer/src/java",
"${projectDir}/../modules/analytics/src/java",
"${projectDir}/../modules/android/src/java",
"${projectDir}/../modules/app/src/java",
"${projectDir}/../modules/calendar/src/java",
"${projectDir}/../modules/contacts/src/java",
"${projectDir}/../modules/database/src/java",
"${projectDir}/../modules/filesystem/src/java",
"${projectDir}/../modules/geolocation/src/java",
"${projectDir}/../modules/gesture/src/java",
"${projectDir}/../modules/locale/src/java",
"${projectDir}/../modules/media/src/java",
"${projectDir}/../modules/network/src/java",
"${projectDir}/../modules/platform/src/java",
"${projectDir}/../modules/ui/src/java",
"${projectDir}/../modules/utils/src/java",
"${projectDir}/../modules/xml/src/java",
"${projectDir}/../runtime/common/src/java",
"${projectDir}/../runtime/v8/src/java"
]
jni.srcDirs = [
"${projectDir}/../runtime/v8/src/native",
"${projectDir}/../runtime/v8/src/native/modules",
"${projectDir}/../runtime/v8/generated"
]
res.srcDirs = [
'res',
"${projectDir}/../modules/ui/res"
]
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
// Downloads/extracts V8 library and creates a cmake file for it. To be executed before C/C++ "build" or "clean".
task updateV8Library() {
def packageJson = new JsonSlurper().parse(file("${projectDir}/../package.json"))
def v8MakeFilePath = "${projectDir}/../runtime/v8/src/ndk-modules/libv8/V8Settings.cmake"
inputs.property 'v8.version', packageJson.v8.version
inputs.property 'v8.mode', packageJson.v8.mode
inputs.property 'v8.integrity', packageJson.v8.integrity
outputs.file v8MakeFilePath
outputs.files fileTree("${projectDir}/../../dist/android/libv8/${packageJson.v8.version}/${packageJson.v8.mode}")
doLast {
// Generate a "V8Settings.cmake" file providing V8 library information via variables.
// This file is referenced by our "./runtime/v8/src/ndk-modules/libv8/CMakeLists.txt" file.
def v8MakeFile = file(v8MakeFilePath)
v8MakeFile.getParentFile().mkdirs()
v8MakeFile.text = [
"set(LIBV8_VERSION \"${packageJson.v8.version}\")",
"set(LIBV8_MODE \"${packageJson.v8.mode}\")"
].join('\n') + '\n'
// Download/install the V8 library referenced in our "package.json", if not already done.
exec {
executable = 'node'
workingDir = projectDir
args = ['-e', "require('./libv8-services').updateLibraryThenExit()"]
}
}
}
preBuild.dependsOn updateV8Library
tasks.withType(ExternalNativeCleanTask) {
dependsOn updateV8Library
}
// Checks our Java code against our style guidelines and for common coding mistakes using "checkstyle.xml".
// Will trigger a build failure if any violations have been detected.
// Customize all the Checkstyle tasks
tasks.withType(Checkstyle) {
// Specify all files that should be checked
classpath = files()
source android.sourceSets.main.java.srcDirs
}
// Execute Checkstyle on all files
task checkJavaStyle(type: Checkstyle) {
// include '**/*.java'
}
// Execute Checkstyle on all modified files
task checkstyleChanged(type: Checkstyle) {
include getChangedFiles()
}
// Used to strip the src dir prefixes from the changed java files
def getChangedFiles() {
if (!project.hasProperty('changedFiles')) {
return new ArrayList<>()
}
def allFiles = project.changedFiles.split(',')
// Remove the prefix
List<String> files = new ArrayList<>()
for (file in allFiles) {
def index = file.indexOf('src/java/')
if (index != -1) {
files.add(file.substring(index + 9))
}
}
// Return the list of touched files
files
}
// Performs a transpile/polyfill/rollup of our "titanium_mobile/common/Resources" directory tree's JS files,
// takes a V8 snapshot of rolled-up files, and then generates a C++ header file of that snapshot to be compiled-in.
// Note: This supports incremental builds. Only executes when JS files change or snapshot output file is missing.
task snapshotTiCommonFiles() {
inputs.dir "${projectDir}/../../common/Resources"
inputs.file "${projectDir}/../../build/lib/builder.js"
inputs.file "${projectDir}/../../build/lib/android/index.js"
outputs.file "${projectDir}/../runtime/v8/generated/V8Snapshots.h"
doLast {
exec {
executable = 'node'
workingDir = projectDir
args = ['-e', "require('./libv8-services').createSnapshotThenExit()"]
}
}
}
// Set up project to compile Java side before compiling the C/C++ side.
// We must do this because our "kroll-apt" Java annotation processor generates C++ source files.
project.afterEvaluate {
externalNativeBuildDebug.dependsOn compileDebugJavaWithJavac
externalNativeBuildRelease.dependsOn compileReleaseJavaWithJavac
buildCMakeDebug.dependsOn compileDebugJavaWithJavac
buildCMakeRelWithDebInfo.dependsOn compileReleaseJavaWithJavac
}
// Runs our "prebuild.js" script before the C/C++ compile, but after Java compile. (Mid-build script?)
// Generates C/C++ files providing our Android-only JS files via byte arrays.
tasks.withType(JavaCompile) {
dependsOn checkJavaStyle
dependsOn snapshotTiCommonFiles
doLast {
exec {
executable = 'node'
workingDir = projectDir
args = ['prebuild.js']
}
}
}
clean.doLast {
// Delete generated C/C++ files.
project.delete file("${projectDir}/../runtime/v8/generated")
// Delete the files copied to our distribution directory. This is what gets packaged/installed.
project.delete fileTree(dir: file("${projectDir}/../../dist/android"), include: '**/*', exclude: 'libv8/**/*')
}
dependencies {
// This reads our code's @Kroll annotations and generates code which interops between V8 and proxy classes.
annotationProcessor project(':kroll-apt')
compileOnly project(':kroll-apt')
// AndroidX Library dependencies.
implementation "androidx.appcompat:appcompat:${project.ext.tiAndroidXAppCompatLibVersion}"
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.core:core:${project.ext.tiAndroidXCoreLibVersion}"
implementation 'androidx.drawerlayout:drawerlayout:1.2.0'
implementation 'androidx.exifinterface:exifinterface:1.3.6'
implementation "androidx.fragment:fragment:${project.ext.tiAndroidXFragmentLibVersion}"
implementation 'androidx.media:media:1.6.0'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.transition:transition:1.4.1'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'androidx.annotation:annotation:1.5.0'
// Google's "Material Components" themed UI library.
implementation "com.google.android.material:material:${project.ext.tiMaterialLibVersion}"
// The Google Play Services libraries are only used by Titanium's geolocation feature.
// We link to them dynamically at runtime. So, they can be safely excluded when in the app project.
implementation "com.google.android.gms:play-services-base:${project.ext.tiPlayServicesBaseLibVersion}"
implementation 'com.google.android.gms:play-services-location:21.0.1'
// XML library providing XPath support to our Ti.XML APIs.
implementation 'jaxen:jaxen:1.2.0'
// WebSocket library is needed to do JavaScript debugging.
implementation 'org.java-websocket:Java-WebSocket:1.5.3'
// Reference all local JAR file dependencies.
implementation fileTree(dir: 'lib', include: ['*.jar'])
// CameraX
def camerax_version = '1.2.3'
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-video:$camerax_version"
implementation "androidx.camera:camera-lifecycle:$camerax_version"
implementation "androidx.camera:camera-view:$camerax_version"
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
// This block is used when we do a "gradlew :titanium:publish", which is invoked by our "node scons package" tool.
// It generates a maven "m2repository" directory tree containing our Titanium AAR and several XML versioning files.
// The below will only work if you do a release build via "gradlew :titanium:assembleRelease" first.
publishing {
publications {
titaniumPublication(MavenPublication) {
// Set up maven repo info.
groupId 'org.appcelerator'
artifactId 'titanium'
version tiBuildVersionString
artifact file("${buildDir}/outputs/aar/titanium-release.aar")
// Generates the "*.pom" XML file containing all of Titanium's above dependencies,
// but excluding Google Play Services dependencies which is optional.
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def list = new ArrayList<Dependency>()
list.addAll(configurations.api.allDependencies)
list.addAll(configurations.implementation.allDependencies)
list.each {
if ((it.group != null) && (it.name != null)) {
if (it.group != 'com.google.android.gms') {
def childNode = dependenciesNode.appendNode('dependency')
childNode.appendNode('groupId', it.group)
childNode.appendNode('artifactId', it.name)
childNode.appendNode('version', it.version)
}
}
}
}
}
}
repositories {
maven {
// The maven directory tree produced above will be outputted to the following local directory.
url "${buildDir}/outputs/m2repository"
}
}
}
publish.doLast {
// After above publishing step, extract C/C++ "*.so" libraries from AAR to "./build/outputs/jniLibs" directory.
def jniLibsOutputDir = "${buildDir}/outputs/jniLibs"
project.delete jniLibsOutputDir
copy {
from zipTree("${buildDir}/outputs/aar/titanium-release.aar")
into jniLibsOutputDir
include 'jni/**/*'
includeEmptyDirs false
eachFile {
it.relativePath = new RelativePath(true, it.relativePath.segments.drop(1))
}
}
}