From 8a5608ab940122ee0cc45242d66f553e58931126 Mon Sep 17 00:00:00 2001 From: Ajin Asokan Date: Tue, 9 Aug 2022 11:59:35 +0530 Subject: [PATCH] feat: use apksigner for v2 v3 signing --- apk.go | 2 +- build.go | 2 +- doctor.go | 25 ++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/apk.go b/apk.go index 66426e1..5d672b3 100644 --- a/apk.go +++ b/apk.go @@ -20,7 +20,7 @@ func alignAPK() { func signAPK(keyStore, storePass, keyAlias *string) { LogI("build", "signing app") - cmd := exec.Command(jarsignerPath, "-verbose", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-storepass", *storePass, "-keystore", *keyStore, filepath.Join("build", "bundle.zip"), *keyAlias) + cmd := exec.Command(apksignerPath, "sign", "--ks-pass", "pass:"+*storePass, "--ks", *keyStore, "--ks-key-alias", *keyAlias, filepath.Join("build", "app.apk")) out, err := cmd.CombinedOutput() if err != nil { LogF("build", string(out)) diff --git a/build.go b/build.go index e894056..4c1703e 100644 --- a/build.go +++ b/build.go @@ -30,8 +30,8 @@ func build() { if *useAAB { buildAAB() } else { - signAPK(keyStore, storePass, keyAlias) alignAPK() + signAPK(keyStore, storePass, keyAlias) } } diff --git a/doctor.go b/doctor.go index fc98ec9..d4b8292 100644 --- a/doctor.go +++ b/doctor.go @@ -14,18 +14,18 @@ import ( var ( // java sdk paths - javaPath string - javaBinPath string - javacPath string - jarsignerPath string + javaPath string + javaBinPath string + javacPath string // android sdk paths - sdkPath string - toolsPath string - zipAlignPath string - aapt2Path string - d8Path string - adbPath string + sdkPath string + toolsPath string + zipAlignPath string + aapt2Path string + d8Path string + apksignerPath string + adbPath string // android java apis androidJar string @@ -40,12 +40,12 @@ func doctor() { LogI("doctor", "java", javaPath) LogI("doctor", "javac", javacPath) - LogI("doctor", "jarsigner", jarsignerPath) LogI("doctor", "sdk", sdkPath) LogI("doctor", "aapt2", aapt2Path) LogI("doctor", "d8", d8Path) LogI("doctor", "zipalign", zipAlignPath) + LogI("doctor", "apksigner", apksignerPath) LogI("doctor", "android jar", androidJar) } @@ -84,6 +84,7 @@ func findSDKs() { aapt2Path = filepath.Join(toolsPath, "aapt2") d8Path = filepath.Join(toolsPath, "d8") zipAlignPath = filepath.Join(toolsPath, "zipalign") + apksignerPath = filepath.Join(toolsPath, "apksigner") adbPath = filepath.Join(sdkPath, "platform-tools", "adb") api := strings.Split(btVersion, ".")[0] androidJar = filepath.Join(sdkPath, "platforms", "android-"+api, "android.jar") @@ -93,12 +94,10 @@ func findSDKs() { if javaPath != "" { javaBinPath = filepath.Join(javaPath, "bin") javacPath = filepath.Join(javaBinPath, "javac") - jarsignerPath = filepath.Join(javaBinPath, "jarsigner") } else { LogW("doctor", "JAVA_HOME was not found in environment") // hope the bin is in path javacPath = "javac" - jarsignerPath = "jarsigner" } }