对jks签名文件进行Base64编码
使用Github Actions构建Android项目需要签名,而jks文件又无法私密保存,故可以将其转为base64格式再设置安全变量 ( https://github.com/{...}/settings/secrets/actions )
openssl base64 < key.jks | tr -d '\r\n' | tee key.jks.base64.txt
.github\workflows\release.yml:
- name: Init Signature
run: |
touch local.properties
echo ALIAS_NAME='${{ secrets.ALIAS_NAME }}' >> local.properties
echo ALIAS_PASSWORD='${{ secrets.ALIAS_PASSWORD }}' >> local.properties
echo KEY_PASSWORD='${{ secrets.KEY_PASSWORD }}' >> local.properties
echo KEY_PATH='./key.jks' >> local.properties
# 从Secrets读取无换行符Base64解码, 然后保存到到app/key.jks
echo ${{ secrets.KEY_STORE }} | base64 --decode > $GITHUB_WORKSPACE/app/key.jks
build.gralde (:app):
signingConfigs {
release {
//签名文件 从local.properties取值
Properties pro = new Properties()
InputStream input = project.rootProject.file("local.properties").newDataInputStream()
pro.load(input)
storeFile file(pro.getProperty("KEY_PATH"))
storePassword pro.getProperty("KEY_PASSWORD")
keyAlias pro.getProperty("ALIAS_NAME")
keyPassword pro.getProperty("ALIAS_PASSWORD")
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
applicationIdSuffix ".debug"
versionNameSuffix "_debug"
}
}
设置Github Actions私有变量:
前往地址: https://github.com/ {user/project} /settings/secrets/actions
分别添加如下四个变量 (Repository secrets):
ALIAS_NAME
别名
ALIAS_PASSWORD
别名密码
KEY_PASSWORD
密码
KEY_STORE
前面生成的base64.jks
参考Github项目地址:https://github.com/jing332/tts-server-android/blob/master/.github/workflows/release.yml