|
| 1 | +import java.io.IOException |
| 2 | +import java.text.SimpleDateFormat |
| 3 | +import java.util.Locale |
| 4 | +import java.util.Date |
| 5 | + |
| 6 | +plugins { |
| 7 | + id("com.android.application") |
| 8 | + id("org.jetbrains.kotlin.android") |
| 9 | + id("com.google.devtools.ksp") |
| 10 | + id("dagger.hilt.android.plugin") |
| 11 | + kotlin("kapt") |
| 12 | + id("com.google.dagger.hilt.android") |
| 13 | + id("kotlin-parcelize") |
| 14 | +} |
| 15 | + |
| 16 | +val baseVersion = "0.0.1" |
| 17 | +val verName = "${baseVersion}.${getGitHash()}" |
| 18 | +val verCode = getGitCommitCount().toInt() |
| 19 | + |
| 20 | +android { |
| 21 | + namespace = "luyao.pay" |
| 22 | + compileSdk = 34 |
| 23 | + |
| 24 | + defaultConfig { |
| 25 | + applicationId = "luyao.pay" |
| 26 | + minSdk = 24 |
| 27 | + targetSdk = 34 |
| 28 | + versionCode = verCode |
| 29 | + versionName = verName |
| 30 | + |
| 31 | + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
| 32 | + |
| 33 | + ksp { |
| 34 | + arg("room.schemaLocation", "$projectDir/schemas") |
| 35 | + arg("room.incremental", "true") |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + signingConfigs { |
| 40 | + create("release") { |
| 41 | + storeFile = file("../key/test") |
| 42 | + storePassword = "123456" |
| 43 | + keyAlias = "test" |
| 44 | + keyPassword = "123456" |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + buildTypes { |
| 49 | + getByName("debug") { |
| 50 | + applicationIdSuffix = ".debug" |
| 51 | + versionNameSuffix = "_debug" |
| 52 | + resValue("string", "app_name", "@string/app_name_debug") |
| 53 | + resValue("string", "package_name", "@string/package_name_debug") |
| 54 | + isMinifyEnabled = false |
| 55 | + isShrinkResources = false |
| 56 | + proguardFiles( |
| 57 | + getDefaultProguardFile("proguard-android-optimize.txt"), |
| 58 | + "proguard-rules.pro" |
| 59 | + ) |
| 60 | + signingConfig = signingConfigs.getByName("release") |
| 61 | + } |
| 62 | + getByName("release") { |
| 63 | + resValue("string", "app_name", "@string/app_name_release") |
| 64 | + resValue("string", "package_name", "@string/package_name_release") |
| 65 | + isMinifyEnabled = true |
| 66 | + isShrinkResources = true |
| 67 | + proguardFiles( |
| 68 | + getDefaultProguardFile("proguard-android-optimize.txt"), |
| 69 | + "proguard-rules.pro" |
| 70 | + ) |
| 71 | + signingConfig = signingConfigs.getByName("release") |
| 72 | + } |
| 73 | + } |
| 74 | + compileOptions { |
| 75 | + sourceCompatibility = JavaVersion.VERSION_17 |
| 76 | + targetCompatibility = JavaVersion.VERSION_17 |
| 77 | + } |
| 78 | + kotlinOptions { |
| 79 | + jvmTarget = JavaVersion.VERSION_17.toString() |
| 80 | + } |
| 81 | + buildFeatures { |
| 82 | + viewBinding = true |
| 83 | + compose = true |
| 84 | + } |
| 85 | + |
| 86 | + composeOptions { |
| 87 | + kotlinCompilerExtensionVersion = "1.5.3" |
| 88 | + } |
| 89 | + |
| 90 | + applicationVariants.all { |
| 91 | + val variant = this |
| 92 | + val time = SimpleDateFormat("yyyyMMddHHmm", Locale.getDefault()).format(Date()) |
| 93 | + variant.outputs.map { |
| 94 | + it as com.android.build.gradle.internal.api.BaseVariantOutputImpl |
| 95 | + }.forEach { |
| 96 | + it.outputFileName = |
| 97 | + "Pay_${variant.flavorName}_${variant.versionName}_" + time + "_" + getGitBranch() + ".apk" |
| 98 | + } |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +dependencies { |
| 103 | + |
| 104 | + implementation(project(":luyao_ktx")) |
| 105 | + |
| 106 | + val composeBom = platform("androidx.compose:compose-bom:2023.10.01") |
| 107 | + implementation(composeBom) |
| 108 | + androidTestImplementation(composeBom) |
| 109 | + implementation("androidx.compose.material3:material3") |
| 110 | + implementation("androidx.compose.ui:ui-tooling-preview") |
| 111 | + debugImplementation("androidx.compose.ui:ui-tooling") |
| 112 | + implementation("androidx.activity:activity-compose:1.8.0") |
| 113 | + implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2") |
| 114 | + implementation("androidx.compose.runtime:runtime-livedata") |
| 115 | + |
| 116 | + val roomVersion = "2.6.0" |
| 117 | + implementation("androidx.room:room-runtime:$roomVersion") |
| 118 | + implementation("androidx.room:room-ktx:$roomVersion") |
| 119 | + ksp("androidx.room:room-compiler:$roomVersion") |
| 120 | + implementation("androidx.preference:preference-ktx:1.2.1") |
| 121 | +// implementation(platform("com.google.firebase:firebase-bom:32.1.1")) |
| 122 | +// implementation("com.google.firebase:firebase-analytics-ktx") |
| 123 | +// implementation("com.google.firebase:firebase-crashlytics-ktx") |
| 124 | +// implementation("com.google.firebase:firebase-perf-ktx") |
| 125 | + |
| 126 | + implementation("com.google.dagger:hilt-android:2.46.1") |
| 127 | + kapt("com.google.dagger:hilt-android-compiler:2.46.1") |
| 128 | + ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.0") |
| 129 | + implementation("com.github.loper7:DateTimePicker:0.6.3") |
| 130 | + implementation("com.github.xkzhangsan:xk-time:3.2.4") |
| 131 | + implementation("de.psdev.licensesdialog:licensesdialog:2.2.0") |
| 132 | + implementation("com.github.tingyik90:snackprogressbar:6.4.2") |
| 133 | + implementation("net.lingala.zip4j:zip4j:2.11.2") |
| 134 | + implementation("com.patrykandpatrick.vico:compose-m3:1.12.0") |
| 135 | + |
| 136 | + testImplementation("junit:junit:4.13.2") |
| 137 | + androidTestImplementation("androidx.test.ext:junit:1.1.5") |
| 138 | + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") |
| 139 | +} |
| 140 | + |
| 141 | +fun getGitBranch(): String { |
| 142 | + return "git symbolic-ref --short -q HEAD".runCommand() |
| 143 | +} |
| 144 | + |
| 145 | +fun getGitHash(): String { |
| 146 | + return "git rev-parse --short HEAD".runCommand() |
| 147 | +} |
| 148 | + |
| 149 | +fun getGitCommitCount(): String { |
| 150 | + return "git rev-list --count HEAD".runCommand() |
| 151 | +} |
| 152 | + |
| 153 | +fun String.runCommand( |
| 154 | + workingDir: File = File("."), |
| 155 | + timeoutAmount: Long = 60, |
| 156 | + timeoutUnit: TimeUnit = TimeUnit.SECONDS |
| 157 | +): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex())) |
| 158 | + .directory(workingDir) |
| 159 | + .redirectOutput(ProcessBuilder.Redirect.PIPE) |
| 160 | + .redirectError(ProcessBuilder.Redirect.PIPE) |
| 161 | + .start() |
| 162 | + .apply { waitFor(timeoutAmount, timeoutUnit) } |
| 163 | + .run { |
| 164 | + val error = errorStream.bufferedReader().readText().trim() |
| 165 | + if (error.isNotEmpty()) { |
| 166 | + throw IOException(error) |
| 167 | + } |
| 168 | + inputStream.bufferedReader().readText().trim() |
| 169 | + } |
0 commit comments