This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
forked from bitrise-steplib/steps-sign-apk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apksignerconfiguration.go
73 lines (59 loc) · 1.82 KB
/
apksignerconfiguration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"os"
"github.com/bitrise-io/go-android/sdk"
)
// SignatureType ..
type SignatureType string
// SignatureType values
const (
KeystoreSignatureType SignatureType = "keystore"
)
// KeystoreSignatureConfiguration ..
type KeystoreSignatureConfiguration struct {
keystorePth string
keystorePassword string
aliasPassword string
alias string
}
// SignatureConfiguration ...
type SignatureConfiguration struct {
apkSigner string
signerScheme string
debuggablePermitted string
signatureType SignatureType
keystoreConfiguration *KeystoreSignatureConfiguration
}
func buildAPKSignerPath() (string, error) {
androidHome := os.Getenv("ANDROID_HOME")
androidSDK, err := sdk.New(androidHome)
if err != nil {
return "", fmt.Errorf("could not locate Android SDK using environment variable ANDROID_HOME='%s': %s", androidHome, err)
}
signer, err := androidSDK.LatestBuildToolPath("apksigner")
if err != nil {
return "", fmt.Errorf("failed to create sdk model: %s", err)
}
return signer, err
}
// NewKeystoreSignatureConfiguration ...
func NewKeystoreSignatureConfiguration(keystore string, keystorePassword string, alias string, aliasPassword string, debuggablePermitted string, signerScheme string) (SignatureConfiguration, error) {
apkSigner, err := buildAPKSignerPath()
if err != nil {
return SignatureConfiguration{}, err
}
keystoreConfig := KeystoreSignatureConfiguration{
keystorePth: keystore,
keystorePassword: keystorePassword,
alias: alias,
aliasPassword: aliasPassword,
}
return SignatureConfiguration{
apkSigner: apkSigner,
debuggablePermitted: debuggablePermitted,
signerScheme: signerScheme,
signatureType: KeystoreSignatureType,
keystoreConfiguration: &keystoreConfig,
}, nil
}