|
| 1 | +apply plugin: 'com.android.application' |
| 2 | +apply plugin: 'org.jetbrains.kotlin.android' |
| 3 | +apply plugin: 'dagger.hilt.android.plugin' |
| 4 | +apply plugin: 'kotlin-kapt' |
| 5 | + |
| 6 | + |
| 7 | +android { |
| 8 | + compileSdk 35 |
| 9 | + namespace "ai.elimu.filamu" |
| 10 | + |
| 11 | + defaultConfig { |
| 12 | + minSdkVersion 26 |
| 13 | + targetSdkVersion 35 |
| 14 | + versionCode 1000000 |
| 15 | + versionName '1.0.0' |
| 16 | + setProperty("archivesBaseName", "${applicationId}-${versionCode}") |
| 17 | + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 18 | + } |
| 19 | + |
| 20 | + buildTypes { |
| 21 | + debug { |
| 22 | + applicationIdSuffix ".debug" |
| 23 | + versionNameSuffix "-debug" |
| 24 | + manifestPlaceholders = [contentProviderApplicationId: "ai.elimu.content_provider.debug"] |
| 25 | + buildConfigField("String", "CONTENT_PROVIDER_APPLICATION_ID", '"ai.elimu.content_provider.debug"') |
| 26 | + buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics.debug"') |
| 27 | + } |
| 28 | + release { |
| 29 | + minifyEnabled false |
| 30 | + manifestPlaceholders = [contentProviderApplicationId: "ai.elimu.content_provider"] |
| 31 | + buildConfigField("String", "CONTENT_PROVIDER_APPLICATION_ID", '"ai.elimu.content_provider"') |
| 32 | + buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics"') |
| 33 | + signingConfig signingConfigs.debug |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + compileOptions { |
| 38 | + sourceCompatibility JavaVersion.VERSION_17 |
| 39 | + targetCompatibility JavaVersion.VERSION_17 |
| 40 | + } |
| 41 | + |
| 42 | + buildFeatures { |
| 43 | + buildConfig = true |
| 44 | + viewBinding = true |
| 45 | + } |
| 46 | + |
| 47 | + kotlinOptions { |
| 48 | + jvmTarget = '17' |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +dependencies { |
| 53 | + implementation fileTree(dir: 'libs', include: ['*.jar']) |
| 54 | + |
| 55 | + implementation project(':data-video') |
| 56 | + implementation libs.elimu.model // See https://jitpack.io/#elimu-ai/model |
| 57 | + implementation libs.elimu.content.provider // See https://jitpack.io/#elimu-ai/content-provider |
| 58 | + implementation libs.elimu.analytics // See https://jitpack.io/#elimu-ai/analytics |
| 59 | + |
| 60 | + implementation libs.androidx.appcompat |
| 61 | + implementation libs.material |
| 62 | + implementation libs.androidx.constraint.layout |
| 63 | + |
| 64 | + implementation libs.androidx.media3.exoplayer |
| 65 | + implementation libs.androidx.media3.ui |
| 66 | + |
| 67 | + implementation libs.glide |
| 68 | + implementation libs.timber |
| 69 | + |
| 70 | + implementation libs.coroutines.android |
| 71 | + implementation libs.coroutines.core |
| 72 | + implementation libs.androidx.core.ktx |
| 73 | + implementation libs.hilt.android |
| 74 | + kapt libs.hilt.compiler |
| 75 | + |
| 76 | + testImplementation libs.junit |
| 77 | + |
| 78 | + androidTestImplementation libs.androidx.junit |
| 79 | + androidTestImplementation libs.androidx.espresso |
| 80 | +} |
| 81 | + |
| 82 | +task ensureCleanRepo { |
| 83 | + doLast { |
| 84 | + if (!grgit.repository.jgit.status().call().clean) { |
| 85 | + throw new GradleException('Git status is not clean, please stash your changes!') |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | +task releaseClean(dependsOn: ensureCleanRepo) { |
| 90 | + doLast { |
| 91 | + def clean = true |
| 92 | + def applicationId = android.defaultConfig.applicationId |
| 93 | + |
| 94 | + String headCommitMessage = grgit.head().shortMessage |
| 95 | + while (headCommitMessage.contains("[gradle-release-task]")) { |
| 96 | + clean = false |
| 97 | + println "Found git commit: $headCommitMessage" |
| 98 | + if (headCommitMessage.indexOf("$applicationId-") > -1) { |
| 99 | + def tagName = headCommitMessage.split("$applicationId-")[1] |
| 100 | + println "Removing the git tag: $tagName" |
| 101 | + try { |
| 102 | + grgit.tag.remove { |
| 103 | + names = [tagName] |
| 104 | + } |
| 105 | + } catch (Exception e) { |
| 106 | + println "Error while removing git tag:\n $e" |
| 107 | + } |
| 108 | + } |
| 109 | + println "Resetting the git commit permanently!" |
| 110 | + grgit.reset(commit: "HEAD~1", mode: "hard") |
| 111 | + headCommitMessage = grgit.head().shortMessage |
| 112 | + |
| 113 | + } |
| 114 | + if (clean){ |
| 115 | + println "Repository is already clean" |
| 116 | + } |
| 117 | + println "Done!" |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +// Task parameters: |
| 122 | +// bumpVersion -> if available will specify new versionName directly and ignores the `bumpType` parameter. |
| 123 | +// bumpType[major|minor|patch] -> will specify how the version bumping occurs. |
| 124 | +task releasePrepare(dependsOn: ensureCleanRepo) { |
| 125 | + doLast { |
| 126 | + def applicationId = android.defaultConfig.applicationId |
| 127 | + def versionName = android.defaultConfig.versionName |
| 128 | + |
| 129 | + if (versionName.indexOf("-") > -1) { |
| 130 | + versionName = versionName.split("-")[0] |
| 131 | + } |
| 132 | + |
| 133 | + // Prepare the release commit with the specific tag. |
| 134 | + String buildText = buildFile.getText() |
| 135 | + buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$versionName'") |
| 136 | + buildFile.setText(buildText) //replace the build file's text |
| 137 | + grgit.add(patterns: ['app/build.gradle']) |
| 138 | + grgit.commit(message: "[gradle-release-task] prepare release $applicationId-$versionName") |
| 139 | + try { |
| 140 | + grgit.tag.add { |
| 141 | + name = versionName |
| 142 | + message = "Release of $versionName" |
| 143 | + } |
| 144 | + } catch (Exception e) { |
| 145 | + throw new GradleException("Failed to tag the repo, error:\n $e") |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | + // Set new version name from input parameters. |
| 150 | + def newVersionName |
| 151 | + if (project.properties.containsKey("bumpVersion")) { |
| 152 | + newVersionName = project.properties["bumpVersion"] |
| 153 | + println "Bumping the version directly (bumpVersion=$newVersionName)" |
| 154 | + } else if (project.properties.containsKey("bumpType")) { |
| 155 | + def (major, minor, patch) = versionName.tokenize('.') |
| 156 | + switch (bumpType) { |
| 157 | + case "major": |
| 158 | + major = major.toInteger() + 1 |
| 159 | + minor = 0 |
| 160 | + patch = 0 |
| 161 | + break |
| 162 | + case "minor": |
| 163 | + minor = minor.toInteger() + 1 |
| 164 | + break |
| 165 | + case "patch": |
| 166 | + patch = patch.toInteger() + 1 |
| 167 | + break |
| 168 | + } |
| 169 | + newVersionName = "$major.$minor.$patch" |
| 170 | + } else { |
| 171 | + throw new GradleException('Either bumpType or bumpVersion parameters should be provided') |
| 172 | + } |
| 173 | + |
| 174 | + // Prepare for next development iteration. |
| 175 | + def versionCode = android.defaultConfig.versionCode |
| 176 | + def newVersionCode = versionCode + 1 |
| 177 | + println "Bumping versionName from $versionName to $newVersionName" |
| 178 | + println "Bumping versionCode from $versionCode to $newVersionCode" |
| 179 | + buildText = buildFile.getText() |
| 180 | + buildText = buildText.replaceFirst(/versionName(\s+.*)/, "versionName '$newVersionName-SNAPSHOT'") |
| 181 | + buildText = buildText.replaceFirst(/versionCode(\s+.*)/, "versionCode $newVersionCode") |
| 182 | + buildFile.setText(buildText) //replace the build file's text |
| 183 | + grgit.add(patterns: ['app/build.gradle']) |
| 184 | + grgit.commit(message: "[gradle-release-task] prepare for next development iteration") |
| 185 | + println "Done!" |
| 186 | + } |
| 187 | + |
| 188 | +} |
| 189 | + |
| 190 | +task releasePerform(dependsOn: ensureCleanRepo) { |
| 191 | + doLast { |
| 192 | + boolean force = false |
| 193 | + if (project.properties.containsKey("force")) { |
| 194 | + force = project.properties["force"] |
| 195 | + } |
| 196 | + println "Pushing the newest commits to the remote repository (force: $force)" |
| 197 | + try { |
| 198 | + grgit.push(force: force, tags: true) |
| 199 | + } catch (Exception e) { |
| 200 | + throw new GradleException("Failed to push to the repo,\n" + |
| 201 | + " you can try using -Pforce=true parameter to force the push, error: \n$e") |
| 202 | + } |
| 203 | + println "Done!" |
| 204 | + } |
| 205 | +} |
0 commit comments