|
1 | 1 | import org.jetbrains.kotlin.config.JvmTarget |
2 | | -import java.io.ByteArrayOutputStream |
3 | 2 | import java.util.Properties |
4 | 3 |
|
5 | 4 | plugins { |
@@ -32,11 +31,25 @@ android { |
32 | 31 | // must correspond to kotlin version: https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility |
33 | 32 | kotlinCompilerExtensionVersion = "1.5.3" |
34 | 33 | } |
| 34 | + signingConfigs { |
| 35 | + readSigningConfig()?.also { config -> |
| 36 | + logger.lifecycle("Use key alias '{}' to sign release", config.keyAlias) |
| 37 | + create("release") { |
| 38 | + storeFile = config.storeFile |
| 39 | + storePassword = "chenhe" |
| 40 | + keyAlias = "weargallery" |
| 41 | + keyPassword = "chenhe" |
| 42 | + |
| 43 | + enableV2Signing = true |
| 44 | + } |
| 45 | + } |
| 46 | + } |
35 | 47 | buildTypes { |
36 | 48 | release { |
37 | 49 | isMinifyEnabled = true |
38 | 50 | isShrinkResources = true |
39 | 51 | proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") |
| 52 | + signingConfigs.findByName("release")?.also { signingConfig = it } |
40 | 53 | } |
41 | 54 | } |
42 | 55 | compileOptions { |
@@ -80,43 +93,24 @@ dependencies { |
80 | 93 | testImplementation("org.json:json:20231013") // JSONObject |
81 | 94 | } |
82 | 95 |
|
83 | | -fun String.runCommand(currentWorkingDir: File = file("./")): String { |
84 | | - val byteOut = ByteArrayOutputStream() |
85 | | - project.exec { |
86 | | - workingDir = currentWorkingDir |
87 | | - commandLine = this@runCommand.split(" ") |
88 | | - standardOutput = byteOut |
89 | | - } |
90 | | - return String(byteOut.toByteArray()).trim() |
91 | | -} |
92 | | - |
93 | | -fun getVersionCode(): Int { |
94 | | - val cmd = "git rev-list HEAD --first-parent --count" |
95 | | - return try { |
96 | | - cmd.runCommand().toInt() |
97 | | - } catch (e: Exception) { |
98 | | - logger.error("Failed to get version code with git, return 1 by default.\n${e.message}") |
99 | | - 1 |
100 | | - } |
101 | | -} |
| 96 | +data class SigningConfig( |
| 97 | + val storeFile: File, |
| 98 | + val storePwd: String, |
| 99 | + val keyAlias: String, |
| 100 | + val keyPwd: String, |
| 101 | +) |
102 | 102 |
|
103 | | - |
104 | | -fun getVersionName(): String { |
105 | | - val cmd = "git describe --tags --long --first-parent --abbrev=7 --dirty=_dev" |
106 | | - try { |
107 | | - val v = cmd.runCommand() |
108 | | - val pattern = """^v(?<v>[\d|.]+)-\d+-g[A-Za-z0-9]{7}(?<s>_dev)?$""".toRegex() |
109 | | - val g = pattern.matchEntire(v)?.groups |
110 | | - if (g == null || g["v"] == null) { |
111 | | - logger.error( |
112 | | - "Failed to get version name with git.\n" + |
113 | | - "Cannot match git tag describe, return <UNKNOWN> by default. raw=$v" |
114 | | - ) |
115 | | - return "UNKNOWN" |
116 | | - } |
117 | | - return g["v"]!!.value + (g["s"]?.value ?: "") |
118 | | - } catch (e: Exception) { |
119 | | - logger.error("Failed to get version name with git, return <UNKNOWN> by default.\n${e.message}") |
120 | | - return "UNKNOWN" |
| 103 | +fun readSigningConfig(): SigningConfig? { |
| 104 | + val path = System.getenv("QNEVO_SIGNING_STORE_PATH") ?: return null |
| 105 | + val f = File(path) |
| 106 | + if (!f.isFile) { |
| 107 | + logger.warn("Key store file not exist: {}", path) |
| 108 | + return null |
121 | 109 | } |
| 110 | + return SigningConfig( |
| 111 | + storeFile = f, |
| 112 | + storePwd = System.getenv("QNEVO_SIGNING_STORE_PWD") ?: return null, |
| 113 | + keyAlias = System.getenv("QNEVO_SIGNING_KEY_ALIAS") ?: return null, |
| 114 | + keyPwd = System.getenv("QNEVO_SIGNING_KEY_PWD") ?: return null |
| 115 | + ) |
122 | 116 | } |
0 commit comments