Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 1 | import groovy.xml.XmlUtil |
| 2 | |
Torsten Grote | 6c53106 | 2020-09-25 10:23:32 -0300 | [diff] [blame] | 3 | plugins { |
| 4 | id "com.android.application" |
| 5 | id "kotlin-android" |
| 6 | id "org.jlleitschuh.gradle.ktlint" version "9.4.0" |
| 7 | } |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 8 | |
Torsten Grote | 7694eb3 | 2020-10-23 10:25:44 -0300 | [diff] [blame] | 9 | def 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 Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 18 | android { |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 19 | |
Torsten Grote | 415b572 | 2020-09-09 16:46:30 -0300 | [diff] [blame] | 20 | compileSdkVersion 30 |
Steve Soltys | 9daaeea | 2020-11-10 16:34:40 -0500 | [diff] [blame] | 21 | buildToolsVersion '30.0.2' |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 22 | |
| 23 | defaultConfig { |
Torsten Grote | 45ac888 | 2020-09-09 18:12:02 -0300 | [diff] [blame] | 24 | minSdkVersion 29 // leave at 29 for robolectric tests |
Torsten Grote | 415b572 | 2020-09-09 16:46:30 -0300 | [diff] [blame] | 25 | targetSdkVersion 30 |
Torsten Grote | 7694eb3 | 2020-10-23 10:25:44 -0300 | [diff] [blame] | 26 | versionNameSuffix "-$gitDescribe" |
Torsten Grote | e955e02 | 2019-08-06 08:16:37 +0200 | [diff] [blame] | 27 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
Torsten Grote | b9cac5e | 2019-12-18 13:14:25 -0300 | [diff] [blame] | 28 | testInstrumentationRunnerArguments disableAnalytics: 'true' |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 29 | } |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 30 | |
| 31 | buildTypes { |
| 32 | release { |
| 33 | minifyEnabled false |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
| 37 | lintOptions { |
Torsten Grote | 57f4042 | 2020-09-14 17:47:01 -0300 | [diff] [blame] | 38 | disable "CheckedExceptions" |
| 39 | abortOnError true |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 40 | } |
| 41 | compileOptions { |
| 42 | targetCompatibility 1.8 |
| 43 | sourceCompatibility 1.8 |
| 44 | } |
Torsten Grote | fcf17fe | 2020-01-18 15:39:53 -0300 | [diff] [blame] | 45 | kotlinOptions { |
| 46 | jvmTarget = JavaVersion.VERSION_1_8.toString() |
| 47 | } |
Torsten Grote | 2ce625a | 2019-07-09 19:22:24 +0200 | [diff] [blame] | 48 | testOptions { |
| 49 | unitTests.all { |
| 50 | useJUnitPlatform() |
| 51 | testLogging { |
| 52 | events "passed", "skipped", "failed" |
| 53 | } |
| 54 | } |
Torsten Grote | b9cac5e | 2019-12-18 13:14:25 -0300 | [diff] [blame] | 55 | unitTests { |
| 56 | includeAndroidResources = true |
| 57 | } |
Torsten Grote | 2ce625a | 2019-07-09 19:22:24 +0200 | [diff] [blame] | 58 | } |
Torsten Grote | d1f5986 | 2019-06-03 15:51:58 -0300 | [diff] [blame] | 59 | |
Torsten Grote | 74aa62a | 2019-08-20 13:04:09 +0200 | [diff] [blame] | 60 | sourceSets { |
| 61 | test { |
| 62 | java.srcDirs += "$projectDir/src/sharedTest/java" |
| 63 | } |
| 64 | androidTest { |
| 65 | java.srcDirs += "$projectDir/src/sharedTest/java" |
| 66 | } |
| 67 | } |
| 68 | |
Chirayu Desai | b08b1f5 | 2021-02-19 22:05:47 +0530 | [diff] [blame^] | 69 | 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 Grote | d1f5986 | 2019-06-03 15:51:58 -0300 | [diff] [blame] | 77 | } |
Torsten Grote | d1f5986 | 2019-06-03 15:51:58 -0300 | [diff] [blame] | 78 | } |
Chirayu Desai | b08b1f5 | 2021-02-19 22:05:47 +0530 | [diff] [blame^] | 79 | |
| 80 | buildTypes.release.signingConfig = signingConfigs.aosp |
| 81 | buildTypes.debug.signingConfig = signingConfigs.aosp |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Torsten Grote | d2ed3a1 | 2020-09-15 17:16:22 -0300 | [diff] [blame] | 84 | apply from: '../gradle/dependencies.gradle' |
| 85 | |
Torsten Grote | 6c53106 | 2020-09-25 10:23:32 -0300 | [diff] [blame] | 86 | ktlint { |
| 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 Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 97 | gradle.projectsEvaluated { |
| 98 | tasks.withType(JavaCompile) { |
Torsten Grote | e659892 | 2019-09-19 11:19:44 -0300 | [diff] [blame] | 99 | if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { |
| 100 | options.compilerArgs.addAll(['--release', '8']) |
| 101 | } |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 102 | options.compilerArgs.add('-Xbootclasspath/p:app/libs/android.jar:app/libs/libcore.jar') |
| 103 | } |
| 104 | } |
| 105 | |
Torsten Grote | b17a55a | 2019-06-11 10:25:36 -0300 | [diff] [blame] | 106 | // http://www.31mins.com/android-studio-build-system-application/ |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 107 | preBuild.doLast { |
| 108 | def imlFile = file(project.name + ".iml") |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 109 | |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 110 | 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 Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 114 | |
Torsten Grote | 6c53106 | 2020-09-25 10:23:32 -0300 | [diff] [blame] | 115 | def apiString = android.compileSdkVersion.substring("android-".length()) |
| 116 | def sdkString = "Android API " + apiString + " Platform" |
Torsten Grote | e659892 | 2019-09-19 11:19:44 -0300 | [diff] [blame] | 117 | //noinspection GroovyResultOfObjectAllocationIgnored // the note gets inserted |
Torsten Grote | 6c53106 | 2020-09-25 10:23:32 -0300 | [diff] [blame] | 118 | new Node(parsedXml.component[1], 'orderEntry', [ |
| 119 | 'type' : 'jdk', |
| 120 | 'jdkName': sdkString, |
| 121 | 'jdkType': 'Android SDK' |
| 122 | ]) |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 123 | XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile)) |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 124 | |
Torsten Grote | 2434fe3 | 2019-06-03 12:23:09 -0300 | [diff] [blame] | 125 | } catch (NullPointerException | FileNotFoundException ex) { |
| 126 | ex.printStackTrace() |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Torsten Grote | d2ed3a1 | 2020-09-15 17:16:22 -0300 | [diff] [blame] | 130 | configurations { |
| 131 | all { |
| 132 | resolutionStrategy { |
| 133 | failOnNonReproducibleResolution() |
| 134 | } |
Torsten Grote | ceac5fc | 2020-09-11 15:42:10 -0300 | [diff] [blame] | 135 | } |
Steve Soltys | e872018 | 2018-11-07 22:04:37 -0500 | [diff] [blame] | 136 | } |