forked from openedx-unsupported/edx-app-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
433 lines (374 loc) · 14.2 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
import org.edx.builder.TaskHelper
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'org.yaml:snakeyaml:1.14'
//Included for NewRelic
classpath "com.newrelic.agent.android:agent-gradle-plugin:5.4.1"
classpath 'com.facebook.testing.screenshot:plugin:0.4'
}
}
apply plugin: 'edxapp'
edx {
platform = ANDROID
}
apply plugin: 'com.android.application'
apply plugin: 'newrelic'
apply plugin: 'com.facebook.testing.screenshot'
apply from: 'jacoco.gradle'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
class AndroidHelper {
def saveProcessedConfig(project, config) {
def path = project.file('assets/config')
path.mkdirs()
def jsonWriter = new FileWriter(path.absolutePath + '/config.json')
def builder = new groovy.json.JsonBuilder(config)
jsonWriter.withWriter {
builder.writeTo(it)
}
}
}
/**
* Computes a semantic version string, e.g. "1.0" or "2.5.7" by parsing git branches or tags.
* Branch name takes priority, otherwise the last annotated tag name will be used.
* @return The semantic version string, or "0.0.1" if we failed to determine one.
*/
def getVersionName = { ->
def description = "0.0.1";
try {
def branch = System.getenv("BRANCH")
if (null == branch || branch.isEmpty()) {
def branchout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
standardOutput = branchout
}
branch = branchout.toString().trim()
}
def hasSemanticVersion = { s ->
// This branch/tag contains a semantic version (e.g. "rc/2.6.0" or "release/2.5")
return s.indexOf("rc/") >= 0 || s.indexOf("release/") >= 0
}
if (hasSemanticVersion(branch)) {
description = branch;
} else {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe'
standardOutput = stdout
}
def describe = stdout.toString().trim()
if (hasSemanticVersion(describe)) {
description = describe;
}
}
}
catch (e) {
logger.error("Could not determine version name", e)
}
return description.substring(description.indexOf("/") + 1).split("-")[0].trim()
}
/**
* @return An integer representation of the string returned by getVersionName()
*/
def getVersionCode = { ->
try {
def versionName = getVersionName()
def semVer = versionName.split('\\.')
def vCode;
vCode = semVer[0].toInteger() * 1000000 // Major version
if (semVer.length > 1) {
vCode += semVer[1].toInteger() * 1000 // Minor version
if (semVer.length > 2) {
vCode += semVer[2].toInteger() * 1 // Patch version
}
}
return vCode
} catch (e) {
logger.error("Could not determine version code", e)
return 1;
}
}
task(version) << {
println String.format('%s (%s)', getVersionName(), getVersionCode())
}
dependencies {
compile project (':android-iconify')
// Note that we have the Font Awesome TTF file
// in the local assets as well, to enable the
// graphical layout editor to render it. Since
// that is what will be compiled in the APK now,
// we need to ensure that it's updated along
// with module updates.
compile project (':android-iconify-fontawesome')
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.facebook.android:facebook-android-sdk:3.23.1'
compile 'com.google.android.gms:play-services-plus:10.0.1'
compile 'com.google.android.gms:play-services-analytics:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'com.google.code.gson:gson:2.7'
compile 'de.greenrobot:eventbus:2.4.1'
compile 'com.squareup.phrase:phrase:1.1.0'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
/* Exclude dependencies defined statically at the top-
* level, to prevent them from being resolved to the
* latest version as a result of dynamic version
* definitions in the transitive dependencies.
*/
compile ('com.squareup.retrofit2:retrofit:2.1.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
compile ('com.squareup.retrofit2:converter-gson:2.1.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
exclude group: 'com.google.code.gson', module: 'gson'
}
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
// Google Firebase
compile 'com.google.firebase:firebase-core:10.0.1'
// Segment Library
compile('com.segment.analytics.android:analytics-core:3.4.0@aar') {
transitive = true
}
compile('com.segment.analytics.android:analytics-integration-google-analytics:3.4.0@aar') {
exclude module: 'play-services-analytics'
transitive = true
}
//Crashlytics Kit
compile('com.crashlytics.sdk.android:crashlytics-core:2.3.8@aar') {
transitive = true
}
//New Relic Integration
compile 'com.newrelic.agent.android:android-agent:5.4.1'
//Include DI framework
compile 'org.roboguice:roboguice:3.0.1'
provided 'org.roboguice:roboblender:3.0.1'
// For the optional Nullable annotation
compile 'com.android.support:support-annotations:25.3.1'
// test project configuration
testCompile 'junit:junit:4.12'
testCompile ("org.mockito:mockito-core:1.10.19"){
exclude group: 'org.hamcrest'
}
testCompile "org.robolectric:robolectric:3.0"
testCompile "org.robolectric:shadows-support-v4:3.0"
testCompile "org.robolectric:shadows-multidex:3.0"
testCompile 'org.assertj:assertj-core:2.5.0'
testCompile ('com.squareup.assertj:assertj-android:1.1.1') {
exclude group: 'com.android.support'
}
testCompile ('com.squareup.assertj:assertj-android-support-v4:1.1.1') {
exclude group: 'com.android.support'
}
testCompile ('com.squareup.assertj:assertj-android-appcompat-v7:1.1.1') {
exclude group: 'com.android.support'
}
testCompile 'com.squareup.okhttp3:mockwebserver:3.0.1'
testCompile ('com.squareup.retrofit2:retrofit-mock:2.1.0') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile "com.crittercism.dexmaker:dexmaker:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:1.4"
androidTestCompile ("org.mockito:mockito-core:1.10.19"){
exclude group: 'org.hamcrest'
}
}
configurations {
androidTestCompile.exclude group: 'com.android.support', module: 'support-annotations'
androidTestCompile.exclude group: 'com.android.support', module: 'multidex'
androidTestCompile.exclude group: 'javax.inject'
androidTestCompile.exclude group: 'javax.annotation'
}
def config = new TaskHelper().loadConfig(project)
// https://developers.google.com/android/guides/google-services-plugin
if (config.get('FIREBASE_ENABLED')?: false) {
apply plugin: 'com.google.gms.google-services'
}
android {
signingConfigs {
releasekey {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
compileSdkVersion COMPILE_SDK_VERSION
buildToolsVersion BUILD_TOOLS_VERSION
dataBinding {
enabled = true
}
dexOptions {
javaMaxHeapSize "2g"
}
defaultConfig {
applicationId "org.edx.mobile"
// minimum version is Android 4.0
minSdkVersion 14
targetSdkVersion 21
versionCode getVersionCode()
versionName getVersionName()
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
// test configuration
testApplicationId 'org.edx.mobile.test'
if (project.gradle.startParameter.taskNames.contains("screenshotTests")) {
Map<String, String> map = new HashMap<String, String>();
map.put("package", "org.edx.mobile.test.screenshot");
setTestInstrumentationRunnerArguments map
}
testInstrumentationRunner "org.edx.mobile.test.EdXTestRunner"
testHandleProfiling true
testFunctionalTest true
testBuildType "debuggable"
// Enabling multidex support.
multiDexEnabled true
manifestPlaceholders = [supportsRtl:"false",
firebaseEnabled: config.get('FIREBASE_ENABLED')?: false]
def platformName = config.get('PLATFORM_NAME')
resValue "string", "platform_name", platformName
def appShortcutName = config.get('APP_SHORTCUT_NAME')
if (appShortcutName == null) {
appShortcutName = platformName
}
resValue "string", "shortcut_name", appShortcutName
def phoneticPlatformName = config.get('PHONETIC_PLATFORM_NAME')
if (phoneticPlatformName == null) {
phoneticPlatformName = platformName
}
resValue "string", "phonetic_platform_name", phoneticPlatformName
def fabric = config.get('FABRIC')
if (fabric?.get('ENABLED')) {
def fabric_key = fabric?.get('FABRIC_KEY')
if (null == fabric_key) {
throw new GradleException("You must set FABRIC_KEY if Fabric is enabled")
} else {
resValue "string", "io.fabric.ApiKey", fabric_key
resValue "bool", "com.crashlytics.RequireBuildId", "false"
}
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml.
// This moves them out of default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
if (project.hasProperty('RES_DIR')) {
prod.res.srcDirs = [RES_DIR]
}
if (project.hasProperty('ASSETS')) {
prod.assets.srcDirs = [ASSETS]
}
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
lintOptions {
abortOnError true
showAll true
warning 'TypographyQuotes', 'InvalidPackage'
error 'StopShip', 'ContentDescription'
}
productFlavors {
prod {
if (project.hasProperty('APPLICATION_ID')) {
applicationId APPLICATION_ID
}
}
dev {
minSdkVersion 21 // Disables multidex to drastically speed up build: https://developer.android.com/tools/building/multidex.html#dev-build
}
}
buildTypes {
debug {
testCoverageEnabled true
pseudoLocalesEnabled true // Set device language to "en_XA" to test glyphs, or "ar_XB" to test RTL support
manifestPlaceholders = [ supportsRtl:"true"]
}
debuggable.initWith(buildTypes.debug)
debuggable {
testCoverageEnabled = false // Set to "false" to work around debugger issue: https://code.google.com/p/android/issues/detail?id=123771
}
release {
signingConfig signingConfigs.releasekey
applicationVariants.all { variant ->
variant.outputs.each { output ->
project.ext { appName = 'edx' }
def newName = output.outputFile.name
newName = newName.replace("OpenEdXMobile-", "$project.ext.appName-")
newName = newName.replace(("-" + variant.buildType.name), ("-" + variant.buildType.name + "-" + versionName))
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'APK LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
testOptions {
unitTests.all {
maxHeapSize '1g'
}
}
}
android.applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
def taskName = "applyConfig" + variantName
def configureTask = project.task(taskName) << {
def helper = new AndroidHelper()
helper.saveProcessedConfig(project, config)
}
def generateTask = project.tasks.getByName("generate" + variantName + "Resources")
generateTask.dependsOn(configureTask)
tasks.all {task ->
if (task.name.startsWith("test")) {
task.mustRunAfter(configureTask)
}
}
}
screenshots {
testApkTarget = 'packageProdDebuggableAndroidTest'
connectedAndroidTestTarget = 'connectedProdDebuggableAndroidTest'
}