forked from mozilla/glean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
275 lines (227 loc) · 10.5 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This is based off:
// https://github.com/mozilla/application-services/blob/c40e2ccb422cf4af9ffdf095149cec34de1d4bef/components/fxa-client/android/build.gradle
import groovy.json.JsonOutput
plugins {
id "com.jetbrains.python.envs" version "0.0.26"
}
apply plugin: 'com.android.library'
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'jacoco'
/*
* This defines the location of the JSON schema used to validate the pings
* created during unit testing. This uses the vendored schema.
*
* Use `bin/update-schema.sh latest` to update it to the latest upstream version.`
*/
File GLEAN_PING_SCHEMA_PATH = file("$rootDir/glean.1.schema.json")
// Set configuration for the glean_parser
ext.allowGleanInternal = true
ext.gleanNamespace = "mozilla.telemetry.glean"
android {
compileSdkVersion rootProject.ext.build.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
targetSdkVersion rootProject.ext.build['targetSdkVersion']
// TODO: 1551691 Get the version from git tag...? Also, we need to select a
// version that won't conflict with legacy glean-ac versions.
buildConfigField("String", "LIBRARY_VERSION", "\"0.1\"")
// Carefully escape the string here so it will support `\` in
// Windows paths correctly.
buildConfigField("String", "GLEAN_PING_SCHEMA_PATH", JsonOutput.toJson(GLEAN_PING_SCHEMA_PATH.path))
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
// Export our rules in debug, as a consumer might still enable proguard/r8
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
withoutLib {
initWith release
}
}
sourceSets {
main.jniLibs.srcDirs += "$buildDir/nativeLibs/android"
test.resources.srcDirs += "$buildDir/rustJniLibs/desktop"
test.resources.srcDirs += "$buildDir/nativeLibs/desktop"
}
// Uncomment to include debug symbols in native library builds.
// packagingOptions { doNotStrip "**/*.so" }
// This is required to support new AndroidX support libraries.
// See mozilla-mobile/android-components#842
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
testOptions {
unitTests.all {
testLogging {
showStandardStreams = true
}
maxHeapSize = "1024m"
}
unitTests {
includeAndroidResources = true
}
}
}
afterEvaluate {
android.sourceSets.debug.jniLibs.srcDirs = android.sourceSets.main.jniLibs.srcDirs
android.sourceSets.release.jniLibs.srcDirs = android.sourceSets.main.jniLibs.srcDirs
android.sourceSets.main.jniLibs.srcDirs = []
jacoco {
toolVersion = "0.8.4"
}
task jacocoTestReport(type: JacocoReport) {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
'**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
def kotlinDebugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def javaDebugTree = fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinDebugTree, javaDebugTree])
executionData.from = fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
])
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
finalizedBy jacocoTestReport
}
}
cargo {
// The directory of the Cargo.toml to build.
module = '../ffi'
// The Android NDK API level to target.
apiLevel = 21
// Where Cargo writes its outputs.
targetDirectory = '../../target'
libname = 'glean_ffi'
targets = rootProject.ext.rustTargets
profile = rootProject.ext.cargoProfile
extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments
}
configurations {
// There's an interaction between Gradle's resolution of dependencies with different types
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
// JUnit test runner. The runtime classpath in the built-in JUnit test runner gets the
// dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
// doesn't provide the JNI dispatch libraries in the correct Java resource directories. I think
// what's happening is that @aar type in `implementation` resolves to the @jar type in
// `testImplementation`, and that it wins the dependency resolution battle.
//
// A workaround is to add a new configuration which depends on the @jar type and to reference
// the underlying JAR file directly in `testImplementation`. This JAR file doesn't resolve to
// the @aar type in `implementation`. This works when invoked via `gradle`, but also sets the
// correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
// Success!
jnaForTest
}
dependencies {
jnaForTest "net.java.dev.jna:jna:$versions.jna@jar"
implementation "net.java.dev.jna:jna:$versions.jna@aar"
// Note: the following version must be kept in sync
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.coroutines"
implementation "androidx.annotation:annotation:$versions.androidx_annotation"
implementation "androidx.lifecycle:lifecycle-extensions:$versions.androidx_lifecycle_extensions"
implementation "androidx.lifecycle:lifecycle-common:$versions.androidx_lifecycle_extensions"
implementation "androidx.work:work-runtime-ktx:$versions.androidx_work"
// We need a compileOnly dependency on the following block of testing
// libraries in order to expose the GleanTestRule to applications/libraries
// using the Glean SDK.
// We can't simply create a separate package otherwise we would need
// to provide a public API for the testing package to access the
// Glean internals, which is something we would not want to do.
compileOnly "junit:junit:$versions.junit"
compileOnly "androidx.work:work-testing:$versions.androidx_work"
// For reasons unknown, resolving the jnaForTest configuration directly
// trips a nasty issue with the Android-Gradle plugin 3.2.1, like `Cannot
// change attributes of configuration ':PROJECT:kapt' after it has been
// resolved`. I think that the configuration is being made a
// super-configuration of the testImplementation and then the `.files` is
// causing it to be resolved. Cloning first dissociates the configuration,
// avoiding other configurations from being resolved. Tricky!
testImplementation files(configurations.jnaForTest.copyRecursive().files)
testImplementation "androidx.test.ext:junit:$versions.androidx_junit"
testImplementation "org.robolectric:robolectric:$versions.robolectric"
testImplementation "org.mockito:mockito-core:$versions.mockito"
testImplementation "androidx.test:core-ktx:$versions.androidx_core"
testImplementation "com.squareup.okhttp3:mockwebserver:$versions.mockwebserver"
testImplementation "org.mozilla.components:support-test:$versions.android_components"
testImplementation "androidx.work:work-testing:$versions.androidx_work"
androidTestImplementation "androidx.test:runner:$versions.androidx_test"
androidTestImplementation "androidx.test.espresso:espresso-core:$versions.androidx_espresso"
}
afterEvaluate {
// The `cargoBuild` task isn't available until after evaluation.
android.libraryVariants.all { variant ->
def productFlavor = ""
variant.productFlavors.each {
productFlavor += "${it.name.capitalize()}"
}
def buildType = "${variant.buildType.name.capitalize()}"
tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"])
// For unit tests.
tasks["process${productFlavor}${buildType}UnitTestJavaRes"].dependsOn(tasks["cargoBuild"])
}
}
apply from: "$rootDir/publish.gradle"
// If using jnaForTestConfiguration
// please also update the corresponding .buildconfig-android.yml
// `publishedArtifacts` property.
ext.configurePublish(
/* jnaForTestConfiguration= */ configurations.jnaForTest
)
task docs(type: org.jetbrains.dokka.gradle.DokkaAndroidTask, overwrite: true) {
moduleName = "glean"
outputDirectory = "$buildDir/../../../build/docs/javadoc"
outputFormat = "html"
jdkVersion = 7
reportUndocumented = true
}
// Generate markdown docs for the collected metrics.
ext.gleanGenerateMarkdownDocs = true
ext.gleanDocsDirectory = "$rootDir/docs/user/collected-metrics"
ext.gleanYamlFiles = [
"$rootDir/glean-core/metrics.yaml",
"$rootDir/glean-core/pings.yaml",
"$rootDir/glean-core/android/metrics.yaml"
]
// Include the glean-gradle-plugin. This is slightly different than what is
// recommended for external users since we are loading it from the same root Gradle
// build.
apply from: '../../gradle-plugin/src/main/groovy/mozilla/telemetry/glean-gradle-plugin/GleanGradlePlugin.groovy'
ext.glean_plugin.apply(project)
// Store the path to the Glean Miniconda installation in a buildConfigField
// so that unit tests can validate JSON schema.
android {
defaultConfig {
buildConfigField(
"String",
"GLEAN_MINICONDA_DIR",
// Carefully escape the string here so it will support `\` in
// Windows paths correctly.
JsonOutput.toJson(project.ext.gleanCondaDir.path)
)
}
}