forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
254 lines (234 loc) · 9.68 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
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
repositories {
maven {
// Path to the Titanium SDK's "m2repository" containing the "titanium.aar" library.
url '<%- tiMavenUrl %>'
}
}
// Path to proxy binding JSON file created by "kroll-apt" annotation processor and used to do C/C++ code generation.
def tiModuleBindingsJsonPath = "${buildDir}/ti-generated/json/<%- moduleName %>.json".toString()
android {
compileSdkVersion <%- compileSdkVersion %>
defaultConfig {
minSdkVersion 19
targetSdkVersion <%- compileSdkVersion %>
versionName '<%- moduleVersion %>'
// Add the following constants to gradle generated "BuildConfig" Java class under module's namespace.
buildConfigField('String', 'TI_MODULE_AUTHOR', <%- '"\\"' + (moduleAuthor || '').replace(/\\/g, '\\\\').replace(/"/g, '\\\\\\"') + '\\""' %>)
buildConfigField('String', 'TI_MODULE_COPYRIGHT', <%- '"\\"' + (moduleCopyright || '').replace(/\\/g, '\\\\').replace(/"/g, '\\\\\\"') + '\\""' %>)
buildConfigField('String', 'TI_MODULE_DESCRIPTION', <%- '"\\"' + (moduleDescription || '').replace(/\\/g, '\\\\').replace(/"/g, '\\\\\\"') + '\\""' %>)
buildConfigField('String', 'TI_MODULE_ID', '"<%- moduleId %>"')
buildConfigField('String', 'TI_MODULE_LICENSE', <%- '"\\"' + (moduleLicense || '').replace(/\\/g, '\\\\').replace(/"/g, '\\\\\\"') + '\\""' %>)
buildConfigField('String', 'TI_MODULE_NAME', '"<%- moduleName %>"')
buildConfigField('String', 'TI_MODULE_VERSION', '"<%- moduleVersion %>"')
// Have the following ${placeholders} replaced in the module's "AndroidManifest.xml" file.
manifestPlaceholders = project.ext.tiManifestPlaceholders
manifestPlaceholders.put('localApplicationId', '${applicationId}') // Legacy placeholder Google no longer supports.
manifestPlaceholders.put('tiapp.properties["id"]', '${applicationId}')
manifestPlaceholders.put("tiapp.properties['id']", '${applicationId}')
aaptOptions {
// Android build tools ignores asset directories with leading underscores, but iOS supports it.
// So, we must redefine ignore string with underscore pattern removed to support this too.
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
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 which is also used to find onAppCreate() method.
arguments = [
'kroll.outputJsonFilePath': tiModuleBindingsJsonPath,
'kroll.outputCppDirPath': "${buildDir}/ti-generated/jni".toString(),
'kroll.jsModuleName': '<%- moduleId %>',
'kroll.tiBindingsJsonFilePath': '<%- tiBindingsJsonPath.replace(/\\/g, '\\\\') %>'
]
}
}
externalNativeBuild {
ndkBuild {
cppFlags '-std=c++14'
arguments.addAll([
'APP_STL:=c++_shared',
"-j${Runtime.runtime.availableProcessors()}".toString(),
'--output-sync=none'
])
}
}
ndk {
abiFilters <%- "'" + moduleArchitectures.join("','") + "'" %>
}
}
externalNativeBuild {
ndkBuild {
path "${projectDir}/src/main/jni/Android.mk"
}
}
sourceSets {
main {
// Android Java code generation templates.
aidl.srcDirs = [
"${projectDir}/../../platform/android/aidl"
]
// These files are added to APK "assets" folder.
assets.srcDirs = [
"${projectDir}/../../platform/android/assets",
"${projectDir}/../../platform/android/bin/assets" // Legacy path used by encrypted-db module.
]
// Java source code directories.
java.srcDirs = [
'src/main/java',
"${projectDir}/../../src",
"${buildDir}/ti-generated/java"
]
// C/C++ source code directories.
jni.srcDirs = [
"${projectDir}/../../jni",
"${projectDir}/src/main/jni",
"${buildDir}/ti-generated/jni"
]
// C/C++ "*.so" dependency library paths. These libraries will be added to the app.
jniLibs.srcDirs = [
"${projectDir}/../../platform/android/jniLibs",
"${projectDir}/../../libs" // Legacy path used by encrypted-db module.
]
// RenderScript "*.rs" files go here.
renderscript.srcDirs = [
"${projectDir}/../../platform/android/rs"
]
// The APK "res" files such as drawables, strings/values XML, etc.
res.srcDirs = [
"${projectDir}/../../platform/android/res"
]
// These files are added as JAR resources. Can be accessed in java via Class.getResourceAsStream() method.
resources {
srcDirs = [
"${projectDir}/../../assets",
"${projectDir}/../../platform/android/resources"
]
excludes = [
'**/*.js',
'README'
]
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
// Exclude the C++ runtime and Titanium kroll libraries for all architectures when packaging the AAR file.
// Avoids app build failure due to library file name collision. (Apps will use "titanium.aar" bundled *.so files.)
packagingOptions {
exclude '/lib/**/libc++_shared.so'
exclude '/lib/**/libkroll-v8.so'
}
}
// Trigger a build failure if an AAR library was found under the "lib" directory.
// While it will compile with the library, Google's build system won't merge the AAR into this module's AAR.
preBuild.doFirst {
def libDirectory = new File("${projectDir}/../../lib")
if (libDirectory.exists()) {
libDirectory.eachFile {
if (it.name.toLowerCase().endsWith('.aar')) {
def errorMessage =
'AAR files are no longer supported under the "lib" directory. ' +
'You must reference AAR libraries via a "build.gradle" file\'s dependencies section instead.'
throw new GradleException(errorMessage)
}
}
}
}
// 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
buildNdkBuildDebug.dependsOn compileDebugJavaWithJavac
buildNdkBuildRelease.dependsOn compileReleaseJavaWithJavac
}
// Hook into Java compile task.
tasks.withType(JavaCompile) {
// Log all Java linting errors/warnings.
options.compilerArgs << "-Xlint:all"
// Execute our "generate-cpp-files.js" script after Java compile to finish generating C++ files.
// Depends on the JSON file produced by our "kroll-apt" Java annotation processor.
// TODO: Our annnotation processor should do ALL of the proxy code generation. Don't piece-meal it.
doLast {
exec {
environment 'TI_MODULE_BINDINGS_JSON_FILE', tiModuleBindingsJsonPath
environment 'TI_MODULE_GENERATED_JNI_DIR', "${projectDir}/build/ti-generated/jni"
environment 'TI_MODULE_GENERATED_JS_DIR', "${projectDir}/build/ti-generated/js"
environment 'TI_MODULE_ID', '<%- moduleId %>'
environment 'TI_MODULE_NAMESPACE', '<%- moduleId.toLowerCase() %>'
environment 'TI_MODULE_TEMPLATE_DIR', '<%- tiSdkModuleTemplateDir.replace(/\\/g, '\\\\') %>'
executable = 'node'
workingDir = projectDir
args = ['generate-cpp-files.js']
}
}
}
// Titanium does not support incremental @Kroll annotation processing. Disable it in kotlin to avoid build warnings.
project.ext['kapt.incremental.apt'] = false
dependencies {
// This reads the code's @Kroll annotations and generates code which interops between V8 and proxy classes.
def krollAptJarPath = '<%- krollAptJarPath.replace(/\\/g, '\\\\') %>'
annotationProcessor files(krollAptJarPath)
compileOnly files(krollAptJarPath)
kapt files(krollAptJarPath)
// Reference this module's local JAR file dependencies.
implementation fileTree(dir: "${projectDir}/../../lib", include: ['*.jar'])
// Reference the main Titanium library.
implementation 'org.appcelerator:titanium:<%- tiSdkVersion %>'
// Reference the core kotlin library.
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
// This block is used when we run "gradlew :module:publish" at the command line.
// Creates maven "m2repository" directory tree containing built AAR and a "*.pom" XML file providing its dependencies.
publishing {
publications {
titaniumPublication(MavenPublication) {
// Set up maven repo info.
groupId '<%- moduleMavenGroupId %>'
artifactId '<%- moduleMavenArtifactId %>'
version '<%- moduleVersion %>'
artifact file("${buildDir}/outputs/aar/${project.name}-release.aar")
// Generates the "*.pom" XML file containing all of Titanium's above dependencies.
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)) {
def childNode = dependenciesNode.appendNode('dependency')
childNode.appendNode('groupId', it.group)
childNode.appendNode('artifactId', it.name)
// Use minimum SDK specified by module manifest.
if ((it.group == 'org.appcelerator') && (it.name == 'titanium')) {
childNode.appendNode('version', '<%- moduleMinSdkVersion %>')
} else {
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"
}
}
}
// Load the module developer's optional "build.gradle" file from "<moduel>/android" directory.
// This gradle file is expected to provide the module's "dependencies".
def moduleBuildGradlePath = "${projectDir}/../../build.gradle"
if (file(moduleBuildGradlePath).exists()) {
apply from: moduleBuildGradlePath
}