command.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package apksigner
  2. import (
  3. "fmt"
  4. "notabug.org/Umnik/GoAndroidSDK/v2/components/executor"
  5. )
  6. func (a Apksigner) BinPath() string {
  7. return a.binPath
  8. }
  9. // SignApk signs apk file
  10. func (a Apksigner) SignApk(in, out string, verity, allowDebug, verbose bool, signer SignerDN) ([]byte, error) {
  11. var args []string
  12. if verbose {
  13. args = append(args, "-v")
  14. }
  15. args = append(args, "--in", in, "--out", out)
  16. if verity {
  17. args = append(args, "--verity-enabled", "true")
  18. }
  19. if !allowDebug {
  20. args = append(args, "--debuggable-apk-permitted", "false")
  21. }
  22. for i := 1; i <= 4; i++ {
  23. args = append(args, fmt.Sprintf("--v%d-signing-enabled", i), "true")
  24. }
  25. args = append(args, "--v1-signer-name", signer.SignerName, "--key", signer.KeyPath, "--cert", signer.CertPath)
  26. return executor.RunSync(a, "sign", args...)
  27. }
  28. // DumpSignatureInfo returns signature info. See ParseDumpSignatureInfoFromBytes
  29. func (a Apksigner) DumpSignatureInfo(apkFile string, noV1 bool) ([]byte, error) {
  30. args := []string{"--verbose", "--print-certs"}
  31. if noV1 {
  32. args = append(args, "--min-sdk-version", "24")
  33. }
  34. args = append(args, apkFile)
  35. return executor.RunSync(a, "verify", args...)
  36. }