Skip to content

Commit 0a32813

Browse files
authored
Update signing.gradle
1 parent e9bcfe6 commit 0a32813

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

signing.gradle

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,30 @@ android {
1111
}
1212

1313
def getString = { String propertyName, String environmentName, String prompt ->
14-
// 尝试从 properties 文件获取,如果不存在则从环境变量获取,再不存在则尝试控制台输入
1514
return properties?.get(propertyName) ?: System.getenv(environmentName) ?:
1615
System.console()?.readLine('\n' + prompt + ': ')
1716
}
1817

19-
// 定义临时密钥库文件的路径
20-
// 这个文件将在 CI/CD 环境中通过 Base64 解码生成
2118
def tempKeystoreFile = file("${rootProject.projectDir}/temp_keystore_release.jks")
2219

23-
// 优先从环境变量 STORE_FILE_BASE64 获取 Base64 编码的密钥库内容
24-
// 这是一个专门为 CI/CD 环境设计的逻辑,避免直接将密钥库文件提交到仓库
2520
if (System.getenv("STORE_FILE_BASE64") != null) {
2621
def keystoreBase64 = System.getenv("STORE_FILE_BASE64")
27-
byte[] decodedBytes = keystoreBase64.decodeBase64() // Groovy 的 String 扩展方法
28-
tempKeystoreFile.writeBytes(decodedBytes) // 将解码后的字节写入临时文件
22+
byte[] decodedBytes = keystoreBase64.decodeBase64()
23+
tempKeystoreFile.writeBytes(decodedBytes)
2924

30-
// 使用临时文件作为 storeFile
3125
storeFile tempKeystoreFile
32-
// 从环境变量获取密码和别名
3326
storePassword System.getenv("STORE_PASSWORD")
3427
keyAlias System.getenv("KEY_ALIAS")
3528
keyPassword System.getenv("KEY_PASSWORD")
3629
} else {
37-
// 如果没有 STORE_FILE_BASE64 环境变量,则回退到原来的逻辑:
38-
// 1. 从 signing.properties 文件读取 (本地开发常用)
39-
// 2. 从环境变量 STORE_FILE (旧的或者备用环境变量名)
40-
// 3. 尝试交互式输入 (CI/CD 环境会失败,因为没有控制台)
41-
4230
def storeFileFromPropsOrEnv = getString('storeFile', 'STORE_FILE', 'Store file')
4331
if (storeFileFromPropsOrEnv != null) {
4432
storeFile storeFileFromPropsOrEnv.with(rootProject.&file)
4533
} else {
46-
// 在 CI/CD 环境中,如果走到这里,说明配置缺失,需要抛出明确的错误
47-
// 这有助于诊断问题,因为 System.console()?.readLine 会返回 null 导致后续签名失败
4834
throw new GradleException("Release signing configuration is incomplete. " +
4935
"Please provide STORE_FILE_BASE64, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD " +
5036
"as environment variables (e.g., GitHub Secrets) or create a 'signing.properties' file.")
5137
}
52-
// 继续使用原来的 getString 逻辑获取密码和别名
5338
storePassword getString('storePassword', 'STORE_PASSWORD', 'Store password')
5439
keyAlias getString('keyAlias', 'KEY_ALIAS', 'Key alias')
5540
keyPassword getString('keyPassword', 'KEY_PASSWORD', 'Key password')

0 commit comments

Comments
 (0)