mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
cmd/gogio: [android] allow custom signature-key
That change makes possible to provide custom PKCS#12 (JKS/PFX) using `-signkey` and the password with `-signpass`. By default the gogio will use the `debug.keystore`, if no key is provided. Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
+39
-25
@@ -548,37 +548,18 @@ func signAPK(tmpDir string, tools *androidTools, bi *buildInfo) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keystore := filepath.Join(home, ".android", "debug.keystore")
|
||||
if _, err := os.Stat(keystore); err != nil {
|
||||
keystore = filepath.Join(tmpDir, "sign.keystore")
|
||||
keytool, err := findKeytool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = runCmd(exec.Command(
|
||||
keytool,
|
||||
"-genkey",
|
||||
"-keystore", keystore,
|
||||
"-storepass", "android",
|
||||
"-alias", "android",
|
||||
"-keyalg", "RSA", "-keysize", "2048",
|
||||
"-validity", "10000",
|
||||
"-noprompt",
|
||||
"-dname", "CN=android",
|
||||
))
|
||||
if err != nil {
|
||||
|
||||
if bi.key == "" {
|
||||
if err := defaultAndroidKeystore(tmpDir, bi); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = runCmd(exec.Command(
|
||||
filepath.Join(tools.buildtools, "apksigner"),
|
||||
"sign",
|
||||
"--ks-pass", "pass:android",
|
||||
"--ks", keystore,
|
||||
"--ks-pass", "pass:"+bi.password,
|
||||
"--ks", bi.key,
|
||||
apkFile,
|
||||
))
|
||||
if err != nil {
|
||||
@@ -587,6 +568,39 @@ func signAPK(tmpDir string, tools *androidTools, bi *buildInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func defaultAndroidKeystore(tmpDir string, bi *buildInfo) error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Use debug.keystore, if exists.
|
||||
bi.key = filepath.Join(home, ".android", "debug.keystore")
|
||||
bi.password = "android"
|
||||
if _, err := os.Stat(bi.key); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Generate new key.
|
||||
bi.key = filepath.Join(tmpDir, "sign.keystore")
|
||||
keytool, err := findKeytool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = runCmd(exec.Command(
|
||||
keytool,
|
||||
"-genkey",
|
||||
"-keystore", bi.key,
|
||||
"-storepass", bi.password,
|
||||
"-alias", "android",
|
||||
"-keyalg", "RSA", "-keysize", "2048",
|
||||
"-validity", "10000",
|
||||
"-noprompt",
|
||||
"-dname", "CN=android",
|
||||
))
|
||||
return err
|
||||
}
|
||||
|
||||
func findNDK(androidHome string) (string, error) {
|
||||
ndks, err := filepath.Glob(filepath.Join(androidHome, "ndk", "*"))
|
||||
if err != nil {
|
||||
|
||||
@@ -23,6 +23,8 @@ type buildInfo struct {
|
||||
tags string
|
||||
target string
|
||||
version int
|
||||
key string
|
||||
password string
|
||||
}
|
||||
|
||||
func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
||||
@@ -47,6 +49,8 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
||||
tags: *extraTags,
|
||||
target: *target,
|
||||
version: *version,
|
||||
key: *signKey,
|
||||
password: *signPass,
|
||||
}
|
||||
return bi, nil
|
||||
}
|
||||
|
||||
@@ -59,4 +59,8 @@ The -work flag prints the path to the working directory and suppress
|
||||
its deletion.
|
||||
|
||||
The -x flag will print all the external commands executed by the gogio tool.
|
||||
|
||||
The -signkey flag specifies the path of the keystore, used for signing Android apk files.
|
||||
|
||||
The -signpass flag specifies the password of the keystore, ignored if -signkey is not provided.
|
||||
`
|
||||
|
||||
+3
-1
@@ -34,7 +34,9 @@ var (
|
||||
linkMode = flag.String("linkmode", "", "set the -linkmode flag of the go tool")
|
||||
extraLdflags = flag.String("ldflags", "", "extra flags to the Go linker")
|
||||
extraTags = flag.String("tags", "", "extra tags to the Go tool")
|
||||
iconPath = flag.String("icon", "", "Specify an icon for iOS and Android")
|
||||
iconPath = flag.String("icon", "", "specify an icon for iOS and Android")
|
||||
signKey = flag.String("signkey", "", "specify the path of the keystore to be used to sign Android apk files.")
|
||||
signPass = flag.String("signpass", "", "specify the password to decrypt the signkey.")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user