-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
355 lines (307 loc) · 18.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
346
347
348
349
350
351
352
353
354
355
buildscript {
ext.kotlin_version = '1.7.21'
ext.kotlin_coroutines_version = '1.6.4'
ext.copyright_message = (new File('COPYRIGHT')).readLines().get(0)
// The version of Ably's client library for Java that we're using.
// Source code: https://github.com/ably/ably-java
// Maven coordinates: groupId 'io.ably', artifactId ':'ably-android'.
ext.ably_core_version = '1.2.31'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Firebase Crashlytics and App Distribution
// see:
// - https://firebase.google.com/docs/crashlytics/get-started?platform=android
// - https://firebase.google.com/docs/app-distribution/android/distribute-gradle
classpath 'com.google.gms:google-services:4.3.15' // 19 January 2023
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' // 15 September 2022
classpath 'com.google.firebase:firebase-appdistribution-gradle:3.2.0' // 19 January 2023
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'org.jlleitschuh.gradle.ktlint' version '11.0.0'
id 'org.jetbrains.dokka' version '1.4.32'
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}
// https://github.com/Kotlin/dokka/issues/2202#issuecomment-950666269
tasks.dokkaHtmlMultiModule.configure {
pluginsMapConfiguration.set(
["org.jetbrains.dokka.base.DokkaBase": """{ "footerMessage": "$copyright_message"}"""]
)
}
logger.lifecycle("Gradle JVM: ${org.gradle.internal.jvm.Jvm.current()}")
// By design, this property is only injected by our adhoc-publish-example-apps workflow, not by other workflows (for example, publish-example-apps).
// This means that when not adhoc-publishing example app builds it will have a value of `null` (org.codehaus.groovy.runtime.NullObject).
final githubBuildMetadata = findProperty("ABLY_BUILD_CONTEXT_BUILD_METADATA")
logger.lifecycle("githubBuildMetadata [${githubBuildMetadata.getClass()}]: $githubBuildMetadata")
allprojects {
// group and version properties are configured here as they're inherited by the maven-publish plugin.
group = 'com.ably.tracking'
// version MUST conform to the Semantic Versioning Specification (https://semver.org/) version 2.0.0
// on incrementing this value, ensure to also increment versionCode in android defaultConfig (also in this file)
version = '1.7.0'
if (githubBuildMetadata) {
version += "+${githubBuildMetadata}"
}
// Values used to publish the SDK to maven repositories.
ext {
PUBLISH_GROUP_ID = group
PUBLISH_ARTIFACT_ID = project.name // This returns the module/project name, like "publishing-sdk".
PUBLISH_VERSION = version
PUBLISH_POM_NAME = "${PUBLISH_GROUP_ID}:${PUBLISH_ARTIFACT_ID}"
}
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username = 'mapbox'
password = property('MAPBOX_DOWNLOADS_TOKEN')
}
}
}
}
subprojects {
// We have to configure android in afterEvaluate because, otherwise, we get a Gradle error.
// https://stackoverflow.com/a/21032272
// Same goes for testImplementation() method.
afterEvaluate { evaluatedSubProject ->
final evaluatedSubProjectIsALibrary = evaluatedSubProject.pluginManager.hasPlugin('com.android.library')
final evaluatedSubProjectIsAnApp = evaluatedSubProject.pluginManager.hasPlugin('com.android.application')
final evaluatedSubProjectIsAnExampleApp = evaluatedSubProjectIsAnApp && evaluatedSubProject.name.contains('example')
final evaluatedSubProjectIsKotlin = evaluatedSubProject.pluginManager.hasPlugin('kotlin-android')
logger.lifecycle("SubProject Evaluation for ${evaluatedSubProject.name}: Library=${evaluatedSubProjectIsALibrary}, App=${evaluatedSubProjectIsAnApp}, ExampleApp=${evaluatedSubProjectIsAnExampleApp}, Kotlin=${evaluatedSubProjectIsKotlin}")
// This is a convention for this Gradle modules/projects in this repository.
// If the name has 'java' on the end (e.g. 'subscribing-sdk-java') or in the
// middle (e.g. 'subscribing-example-java-app') then it is intended to either
// contain Java source code (example app implementation) or contain interfaces
// which provide support to Java users ('-java' as a suffix).
final evaluatedSubProjectIsJava = evaluatedSubProject.name.contains('-java')
// Dokka configuration for modules
// "The configuration must be done both for the subprojects (pages generated for packages, classes, etc.) and for the overall dokka multi-module task."
// See https://github.com/Kotlin/dokka/issues/2202#issuecomment-950136122 for more
final evaluatedSubProjectHasDokkaPlugin = evaluatedSubProject.pluginManager.hasPlugin('org.jetbrains.dokka')
if (evaluatedSubProjectHasDokkaPlugin) {
tasks.withType(dokkaHtmlPartial.getClass()).configureEach {
pluginsMapConfiguration.set(
["org.jetbrains.dokka.base.DokkaBase": """{ "footerMessage": "$copyright_message"}"""]
)
}
}
android {
compileSdkVersion 33
buildToolsVersion '33.0.1'
packagingOptions {
// If we don't exclude 'META-INF/*' then `./gradlew/connectedCheck` fails with:
// Execution failed for task ':core-sdk-java:mergeDebugAndroidTestJavaResource'.
// > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
// > 12 files found with path 'META-INF/INDEX.LIST' from inputs:
// - /Users/quintinwillison/.gradle/caches/transforms-3/ae58b6a62ada6747292af50f47ad3fee/transformed/jetified-netty-codec-http2-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/f1236fea4dbae41bc32ac55a85f6b3bd/transformed/jetified-netty-transport-native-kqueue-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/3bde7caee3288eeec736343e1ef6bcf9/transformed/jetified-netty-transport-native-epoll-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/12e69c78bc747486c940da51810bfd9c/transformed/jetified-netty-codec-http-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/d4184ed97d39c5a1d0b706dbbe0dbf35/transformed/jetified-netty-handler-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/99bb3b8608be9c2bd59c61265d224fb6/transformed/jetified-netty-codec-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/fc3f8bcdefe05d515a75cd71c6757335/transformed/jetified-netty-transport-classes-kqueue-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/e7af7f748138f134013b272874950077/transformed/jetified-netty-transport-classes-epoll-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/fd2e0a57576bd59a1650c0494ab3fc0a/transformed/jetified-netty-transport-native-unix-common-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/0fd5b682236ce9fd53e58aecc05a5ffd/transformed/jetified-netty-transport-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/1502ea043ca2e82ce79bfa06181a8a4d/transformed/jetified-netty-buffer-4.1.86.Final.jar
// - /Users/quintinwillison/.gradle/caches/transforms-3/a7a5476cb4601d76f24b1d349745bfe6/transformed/jetified-netty-resolver-4.1.86.Final.jar
// Adding a packagingOptions block may help, please refer to
// https://developer.android.com/reference/tools/gradle-api/7.3/com/android/build/api/dsl/ResourcesPackagingOptions
// for more information //
// from: https://stackoverflow.com/a/68136374
exclude 'META-INF/*'
}
defaultConfig {
minSdkVersion((evaluatedSubProjectIsJava || evaluatedSubProjectIsAnExampleApp) ? 24 : 21)
targetSdkVersion 33
// We have no reason not to match versions assigned to all artifacts generated by
// projects in this repository. Therefore, this same version number is used for SDK and
// example app projects alike.
// - versionCode MUST be incremented by 1 for each release from the main branch
versionCode 42
versionName version
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
if (evaluatedSubProjectIsAnApp) {
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
if (evaluatedSubProjectIsKotlin) {
kotlinOptions {
jvmTarget = '1.8'
allWarningsAsErrors = true
freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn'
}
}
// https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/LintOptions
// http://tools.android.com/tips/lint-checks
lintOptions {
warningsAsErrors true
checkTestSources true
// More accessible output, when run from command line and in CI/CD environments.
textReport true
textOutput 'stdout'
explainIssues false
// Lint rules which we might care about at some point, but need not fail the build.
informational 'GradleDependency',
'NewerVersionAvailable',
'AllowBackup',
'VectorPath',
'ContentDescription',
'UnusedResources',
'UnpackedNativeCode',
'LockedOrientationActivity',
'IconLocation',
'StopShip',
'DefaultLocale',
'ObsoleteSdkInt',
'MonochromeLauncherIcon'
// Lint rules which are disabled by default (see: lint --show), but which we would
// rather were enabled.
error 'MissingRegistered',
'Registered',
'WrongThreadInterprocedural',
'MinSdkTooLow',
'MangledCRLF',
'EasterEgg',
'LogConditional',
'UnusedIds'
}
// https://developer.android.com/studio/build/build-variants#build-types
buildTypes {
// Helper function allowing to create our custom DSL and hide setting the delegate
def apply = { action ->
[on: { delegateObject ->
action.delegate = delegateObject
action()
}]
}
def secretConfigFields = {
// Configuration that must not be applied to SDK project main source set builds for the release variant/buildType.
// This configuration is, however, required for Android's connectedCheck task (which uses the androidTest source set
// with the debug variant/buildType).
if (findProperty('runtimeSecrets') == 'USE_DUMMY_EMPTY_STRING_VALUES') {
// We know that we're not going to need to compile anything that needs BuildConfig to contain
// any of these secrets. For example, unit test runs, where we know there are no system tests
// being run or app builds being made where those apps embed secrets.
logger.lifecycle("Using dummy, empty-string secrets configuration (ABLY_API_KEY and MAPBOX_ACCESS_TOKEN) for the '${delegate.name}' Android build type.")
buildConfigField 'String', 'ABLY_API_KEY', "\"\""
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', "\"\""
return
}
final ABLY_API_KEY = findProperty('ABLY_API_KEY')
final MAPBOX_ACCESS_TOKEN = findProperty('MAPBOX_ACCESS_TOKEN')
if (ABLY_API_KEY == null || ABLY_API_KEY.trim().length() < 1) {
throw new GradleException('ABLY_API_KEY not specified or is empty.')
}
if (MAPBOX_ACCESS_TOKEN == null || MAPBOX_ACCESS_TOKEN.trim().length() < 1) {
throw new GradleException('MAPBOX_ACCESS_TOKEN not specified or is empty.')
}
buildConfigField 'String', 'ABLY_API_KEY', "\"${ABLY_API_KEY}\""
buildConfigField 'String', 'MAPBOX_ACCESS_TOKEN', "\"${MAPBOX_ACCESS_TOKEN}\""
logger.lifecycle("Secrets have been added to BuildConfig (ABLY_API_KEY and MAPBOX_ACCESS_TOKEN) for the '${delegate.name}' Android build type.")
}
def versionConfigFields = {
// Android library modules don't have access to both versionName and versionCode fields
// so we're adding them by ourselves.
buildConfigField "String", "VERSION_NAME", "\"${defaultConfig.versionName}\""
buildConfigField "long", "VERSION_CODE", "${defaultConfig.versionCode}"
}
debug {
// Secrets must not be injected into SDK builds - they are only for example apps or SDK
// integration tests (via Android's `connectedCheck` task), which are testing using the debug
// variant/buildType.
if (evaluatedSubProjectIsAnApp || findProperty('runtimeSecrets') == 'FOR_ALL_PROJECTS_BECAUSE_WE_ARE_RUNNING_INTEGRATION_TESTS') {
apply secretConfigFields on it
}
if (evaluatedSubProjectIsALibrary) {
apply versionConfigFields on it
}
//Clear text traffic is required for the NetworkConnectivityTests to work
manifestPlaceholders = [usesCleartextTraffic:"true"]
}
release {
// Secrets must not be injected into SDK builds - they are only for example apps or SDK
// integration tests (via Android's `connectedCheck` task), which are testing using the debug
// variant/buildType.
if (evaluatedSubProjectIsAnApp || findProperty('runtimeSecrets') == 'FOR_ALL_PROJECTS_BECAUSE_WE_ARE_RUNNING_INTEGRATION_TESTS') {
apply secretConfigFields on it
}
if (evaluatedSubProjectIsALibrary) {
apply versionConfigFields on it
}
manifestPlaceholders = [usesCleartextTraffic:"false"]
minifyEnabled false
}
}
}
// https://github.com/jlleitschuh/ktlint-gradle#configuration
ktlint {
verbose = true // shows rule name that failed
android = true
outputColorName = 'RED' // easier to spot failures in console output
disabledRules = [
// according to a Github issue comment this issue could be resolved with Kotlin 1.4
// https://github.com/pinterest/ktlint/issues/527#issuecomment-705871614
'import-ordering',
]
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.7.0'
constraints {
implementation('androidx.fragment:fragment:1.5.5') {
because("The older 1.4 version uses Lint API version 11 but we're running 13 (7.3+), which was triggering ObsoleteLintCustomCheck to fail lintDebug.")
}
}
if (evaluatedSubProjectIsKotlin) {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version'
// Projects that use our SDK projects will crash when dispatching to the Main thread on
// the Android runtime unless we include this dependency. See:
// https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
testImplementation 'io.mockk:mockk:1.12.2'
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
} else {
testImplementation 'org.mockito:mockito-core:3.6.28'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:$kotlin_coroutines_version"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:$kotlin_coroutines_version"
}
if (evaluatedSubProjectIsAnApp) {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.jakewharton.timber:timber:4.7.1'
}
testImplementation 'junit:junit:4.13.2'
testImplementation "com.google.truth:truth:1.1.3"
testImplementation project(':test-common')
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation project(':android-test-common')
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply from: "maven-central.gradle"