{"record":{"id":"bb304de3ae1a7f39","repo":"shwenzhang/AndResGuard","slug":"ks-and-key-may-not-be-specified-at-the-same-time","errorCode":null,"errorMessage":"--ks and --key may not be specified at the same time","messagePattern":"--ks and --key may not be specified at the same time","errorType":"validation","errorClass":"ParameterException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/apksigner/ApkSignerTool.java","lineNumber":634,"sourceCode":"             && (keystoreFile == null)\n             && (keystoreKeyAlias == null)\n             && (keystorePasswordSpec == null)\n             && (keyPasswordSpec == null)\n             && (keystoreType == null)\n             && (keystoreProviderName == null)\n             && (keystoreProviderClass == null)\n             && (keystoreProviderArg == null)\n             && (keyFile == null)\n             && (certFile == null)\n             && (v1SigFileBasename == null)\n             && (privateKey == null)\n             && (certs == null);\n    }\n\n    private void loadPrivateKeyAndCerts(PasswordRetriever passwordRetriever) throws Exception {\n      if (keystoreFile != null) {\n        if (keyFile != null) {\n          throw new ParameterException(\"--ks and --key may not be specified at the same time\");\n        } else if (certFile != null) {\n          throw new ParameterException(\"--ks and --cert may not be specified at the same time\");\n        }\n        loadPrivateKeyAndCertsFromKeyStore(passwordRetriever);\n      } else if (keyFile != null) {\n        loadPrivateKeyAndCertsFromFiles(passwordRetriever);\n      } else {\n        throw new ParameterException(\"KeyStore (--ks) or private key file (--key) must be specified\");\n      }\n    }\n\n    private void loadPrivateKeyAndCertsFromKeyStore(PasswordRetriever passwordRetriever) throws Exception {\n      if (keystoreFile == null) {\n        throw new ParameterException(\"KeyStore (--ks) must be specified\");\n      }\n\n      // 1. Obtain a KeyStore implementation\n      String ksType = (keystoreType != null) ? keystoreType : KeyStore.getDefaultType();","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/apksigner/ApkSignerTool.java#L616-L652","documentation":"ApkSignerTool's loadPrivateKeyAndCerts accepts signing credentials from either a Java KeyStore (--ks) or raw private key/cert files (--key/--cert), never both. When both keystoreFile and keyFile are set it throws this ParameterException before doing any work, because the two credential sources are mutually exclusive by design.","triggerScenarios":"Running apksigner sign with both --ks <keystore> and --key <pk8/pem file> on the same command line.","commonSituations":"Copy-pasting a signing command from two different CI templates; migrating from keystore-based to file-based signing but forgetting to remove --ks; an alias or script that appends --key while --ks is already set.","solutions":["Remove the --ks/--ks-key-id options if you intend file-based signing, keeping only --key and --cert.","Remove --key/--cert if you intend KeyStore-based signing, keeping --ks (plus --ks-key-alias and passwords).","Fix the wrapping script/alias so it only passes one credential source."],"exampleFix":"// before\napksigner sign --ks release.jks --ks-key-alias mykey --key release.pk8 --cert release.x509.pem app.apk\n// after (KeyStore mode)\napksigner sign --ks release.jks --ks-key-alias mykey app.apk","handlingStrategy":"validation","validationCode":"// shell pre-check before invoking apksigner\nif [ -n \"$KS_ARG\" ] && [ -n \"$KEY_ARG\" ]; then\n  echo \"ERROR: use either --ks OR --key/--cert, not both\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define exactly one signing mode (keystore vs pk8/pem files) per build pipeline.","Keep signing flags in a single sourced config file so they cannot be double-appended."],"tags":["cli","apksigner","conflicting-options"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"e4df245d82f27d9a2d0dd108260a3510cbaba849","analyzedAt":"2026-09-12T17:49:07.798Z","contentChangedAt":"2026-09-12T17:49:07.798Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}