blob: 3159d385e070f46aefda6a2b6bb18abd591d20b5 [file] [log] [blame]
Steve Soltyse8720182018-11-07 22:04:37 -05001import groovy.xml.XmlUtil
2
Torsten Grote6c531062020-09-25 10:23:32 -03003plugins {
4 id "com.android.application"
5 id "kotlin-android"
6 id "org.jlleitschuh.gradle.ktlint" version "9.4.0"
7}
Steve Soltyse8720182018-11-07 22:04:37 -05008
Torsten Grote7694eb32020-10-23 10:25:44 -03009def gitDescribe = { ->
10 def stdout = new ByteArrayOutputStream()
11 exec {
12 commandLine 'git', 'describe', '--always', '--tags', '--dirty=-dirty'
13 standardOutput = stdout
14 }
15 return stdout.toString().trim()
16}
17
Steve Soltyse8720182018-11-07 22:04:37 -050018android {
Torsten Grote2434fe32019-06-03 12:23:09 -030019
Torsten Grote415b5722020-09-09 16:46:30 -030020 compileSdkVersion 30
Steve Soltys9daaeea2020-11-10 16:34:40 -050021 buildToolsVersion '30.0.2'
Torsten Grote2434fe32019-06-03 12:23:09 -030022
23 defaultConfig {
Torsten Grote45ac8882020-09-09 18:12:02 -030024 minSdkVersion 29 // leave at 29 for robolectric tests
Torsten Grote415b5722020-09-09 16:46:30 -030025 targetSdkVersion 30
Torsten Grote7694eb32020-10-23 10:25:44 -030026 versionNameSuffix "-$gitDescribe"
Torsten Grotee955e022019-08-06 08:16:37 +020027 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Torsten Groteb9cac5e2019-12-18 13:14:25 -030028 testInstrumentationRunnerArguments disableAnalytics: 'true'
Torsten Grote2434fe32019-06-03 12:23:09 -030029 }
Steve Soltyse8720182018-11-07 22:04:37 -050030
31 buildTypes {
32 release {
33 minifyEnabled false
Steve Soltyse8720182018-11-07 22:04:37 -050034 }
35 }
36
37 lintOptions {
Torsten Grote57f40422020-09-14 17:47:01 -030038 disable "CheckedExceptions"
39 abortOnError true
Steve Soltyse8720182018-11-07 22:04:37 -050040 }
41 compileOptions {
42 targetCompatibility 1.8
43 sourceCompatibility 1.8
44 }
Torsten Grotefcf17fe2020-01-18 15:39:53 -030045 kotlinOptions {
46 jvmTarget = JavaVersion.VERSION_1_8.toString()
47 }
Torsten Grote2ce625a2019-07-09 19:22:24 +020048 testOptions {
49 unitTests.all {
50 useJUnitPlatform()
51 testLogging {
52 events "passed", "skipped", "failed"
53 }
54 }
Torsten Groteb9cac5e2019-12-18 13:14:25 -030055 unitTests {
56 includeAndroidResources = true
57 }
Torsten Grote2ce625a2019-07-09 19:22:24 +020058 }
Torsten Groted1f59862019-06-03 15:51:58 -030059
Torsten Grote74aa62a2019-08-20 13:04:09 +020060 sourceSets {
61 test {
62 java.srcDirs += "$projectDir/src/sharedTest/java"
63 }
64 androidTest {
65 java.srcDirs += "$projectDir/src/sharedTest/java"
66 }
67 }
68
Chirayu Desaib08b1f52021-02-19 22:05:47 +053069 signingConfigs {
70 aosp {
71 // Generated from the AOSP platform key:
72 // https://android.googlesource.com/platform/build/+/refs/tags/android-11.0.0_r29/target/product/security/platform.pk8
73 keyAlias "platform"
74 keyPassword "platform"
75 storeFile file("platform.jks")
76 storePassword "platform"
Torsten Groted1f59862019-06-03 15:51:58 -030077 }
Torsten Groted1f59862019-06-03 15:51:58 -030078 }
Chirayu Desaib08b1f52021-02-19 22:05:47 +053079
80 buildTypes.release.signingConfig = signingConfigs.aosp
81 buildTypes.debug.signingConfig = signingConfigs.aosp
Steve Soltyse8720182018-11-07 22:04:37 -050082}
83
Torsten Groted2ed3a12020-09-15 17:16:22 -030084apply from: '../gradle/dependencies.gradle'
85
Torsten Grote6c531062020-09-25 10:23:32 -030086ktlint {
87 version = "0.36.0" // https://github.com/pinterest/ktlint/issues/764
88 android = true
89 enableExperimentalRules = false
90 verbose = true
91 disabledRules = [
92 "import-ordering",
93 "no-blank-line-before-rbrace",
94 ]
95}
96
Steve Soltyse8720182018-11-07 22:04:37 -050097gradle.projectsEvaluated {
98 tasks.withType(JavaCompile) {
Torsten Grotee6598922019-09-19 11:19:44 -030099 if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
100 options.compilerArgs.addAll(['--release', '8'])
101 }
Steve Soltyse8720182018-11-07 22:04:37 -0500102 options.compilerArgs.add('-Xbootclasspath/p:app/libs/android.jar:app/libs/libcore.jar')
103 }
104}
105
Torsten Groteb17a55a2019-06-11 10:25:36 -0300106// http://www.31mins.com/android-studio-build-system-application/
Torsten Grote2434fe32019-06-03 12:23:09 -0300107preBuild.doLast {
108 def imlFile = file(project.name + ".iml")
Steve Soltyse8720182018-11-07 22:04:37 -0500109
Torsten Grote2434fe32019-06-03 12:23:09 -0300110 try {
111 def parsedXml = (new XmlParser()).parse(imlFile)
112 def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
113 parsedXml.component[1].remove(jdkNode)
Steve Soltyse8720182018-11-07 22:04:37 -0500114
Torsten Grote6c531062020-09-25 10:23:32 -0300115 def apiString = android.compileSdkVersion.substring("android-".length())
116 def sdkString = "Android API " + apiString + " Platform"
Torsten Grotee6598922019-09-19 11:19:44 -0300117 //noinspection GroovyResultOfObjectAllocationIgnored // the note gets inserted
Torsten Grote6c531062020-09-25 10:23:32 -0300118 new Node(parsedXml.component[1], 'orderEntry', [
119 'type' : 'jdk',
120 'jdkName': sdkString,
121 'jdkType': 'Android SDK'
122 ])
Torsten Grote2434fe32019-06-03 12:23:09 -0300123 XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
Steve Soltyse8720182018-11-07 22:04:37 -0500124
Torsten Grote2434fe32019-06-03 12:23:09 -0300125 } catch (NullPointerException | FileNotFoundException ex) {
126 ex.printStackTrace()
Steve Soltyse8720182018-11-07 22:04:37 -0500127 }
128}
129
Torsten Groted2ed3a12020-09-15 17:16:22 -0300130configurations {
131 all {
132 resolutionStrategy {
133 failOnNonReproducibleResolution()
134 }
Torsten Groteceac5fc2020-09-11 15:42:10 -0300135 }
Steve Soltyse8720182018-11-07 22:04:37 -0500136}