Skip to content

Commit

Permalink
配置签名
Browse files Browse the repository at this point in the history
  • Loading branch information
AoEiuV020 committed Mar 12, 2021
1 parent 8668bc7 commit 2125168
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ jobs:
echo "::set-output name=nameWithVersion::$(cat nameWithVersion)"
rm nameWithVersion
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: sign config
run: |
echo "${{ secrets.SIGNING_KEY }}" |base64 -d > signing.jks
echo "${{ secrets.KEY_PROPERTIES }}" > key.properties
echo storeFile=signing.jks >> key.properties
- name: Build with Gradle
- run: |
run: |
mkdir -p build
chmod +x gradlew
./gradlew assembleRelease
Expand Down
53 changes: 53 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,59 @@ android {
versionCode 1
versionName "1.0"
}
// debug和release使用相同签名,以便用debug包覆盖release包从而调试,
// 如果没有,就会使用默认debug签名,
def signingFile = rootProject.file('key.properties')
String sha1 = null
if (signingFile.exists()) {
def input = signingFile.newInputStream()
def p = new Properties()
p.load(input)
input.close()
// 签名文件存在才配置签名,
def jks = rootProject.file(p['storeFile'])
if (jks.exists()) {
signingConfigs {
config {
keyAlias p['keyAlias']
keyPassword p['keyPassword']
storeFile jks
storePassword p['storePassword']
v1SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
debug.signingConfig signingConfigs.config
release.signingConfig signingConfigs.config
}
def signingConfig = signingConfigs.config
if (signingConfig != null) {
//noinspection UnnecessaryQualifiedReference
def keyStore = java.security.KeyStore.getInstance(
signingConfig.getStoreType() != null ?
signingConfig.getStoreType() : KeyStore.getDefaultType())
FileInputStream fis = new FileInputStream(signingConfig.getStoreFile())
keyStore.load(fis, signingConfig.getStorePassword().toCharArray())
fis.close()
char[] keyPassword = signingConfig.getKeyPassword().toCharArray()
//noinspection UnnecessaryQualifiedReference
def entry = keyStore.getEntry(
signingConfig.getKeyAlias(),
new java.security.KeyStore.PasswordProtection(keyPassword))
if (entry != null) {
//noinspection UnnecessaryQualifiedReference
def digest = java.security.MessageDigest.getInstance("SHA-1")
sha1 = digest.digest(entry.getCertificate().encoded).encodeHex().toString()
}
}
}
}
if (sha1 == null) {
defaultConfig.buildConfigField('String', "SIGNATURE", 'null')
} else {
defaultConfig.buildConfigField('String', "SIGNATURE", '"' + sha1 + '"')
}
buildTypes {
release {
minifyEnabled false
Expand Down

0 comments on commit 2125168

Please sign in to comment.