{"record":{"id":"1df6c687d82caf42","repo":"Tencent/matrix","slug":"sign-apk-occur-error","errorCode":null,"errorMessage":"sign apk occur error!","messagePattern":"sign apk occur error!","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-gradle-plugin/src/main/java/com/tencent/matrix/shrinker/ApkUtil.java","lineNumber":372,"sourceCode":"                \"--ks-pass\", \"pass:\" + signingConfig.getStorePassword(),\n                \"--key-pass\", \"pass:\" + signingConfig.getKeyPassword(),\n                \"--ks-key-alias\", signingConfig.getKeyAlias()));\n\n        if (signingConfig.isV1SigningEnabled()) {\n            commandList.add(\"--v1-signing-enabled\");\n        }\n\n        if (signingConfig.isV2SigningEnabled()) {\n            commandList.add(\"--v2-signing-enabled\");\n        }\n        commandList.add(apkFilePath);\n        processBuilder.command(commandList);\n        //Log.i(TAG, \"%s\", processBuilder.command())\n        Process process = processBuilder.start();\n//        process.waitForProcessOutput(System.out, System.err);\n        waitForProcessOutput(process);\n        if (process.exitValue() != 0) {\n            throw new GradleException(\"sign apk occur error!\");\n        }\n    }\n\n    public static void zipAlignApk(String inputFile, String outputFile, String zipAlignPath) throws GradleException, IOException, InterruptedException {\n        ProcessBuilder processBuilder = new ProcessBuilder();\n        processBuilder.command(zipAlignPath, \"-f\", \"4\", inputFile, outputFile);\n        Process process = processBuilder.start();\n//        process.waitForProcessOutput(System.out, System.err);\n        waitForProcessOutput(process);\n        if (process.exitValue() != 0) {\n            throw new GradleException(\"zipalign apk occur error!\");\n        }\n    }\n\n}","sourceCodeStart":354,"sourceCodeEnd":387,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-gradle-plugin/src/main/java/com/tencent/matrix/shrinker/ApkUtil.java#L354-L387","documentation":"Thrown by ApkUtil.signApk after executing an external apksigner/jarsigner command to sign the shrunk APK; any non-zero exit status becomes GradleException('sign apk occur error!'). The signing tool's stdout/stderr is consumed by waitForProcessOutput, so the root cause is in the process output. It means the APK was not signed successfully.","triggerScenarios":"Calling signApk(...) when the keystore path/password/alias is wrong, the signing tool (apksigner/jarsigner) path is invalid, the JDK keytool is missing, the keystore file doesn't exist, or the APK was modified after an earlier signature making signing fail.","commonSituations":"CI environments with missing or wrong signingConfig credentials; expired keystore passwords after a change; using JDK without jarsigner on PATH; v1/v2 signing scheme incompatibilities with older build tools.","solutions":["Re-run with gradle --info or execute the same apksigner command manually to see the signer's real error","Verify keystore file path, store password, key alias and key password in the Matrix shrinker config are correct","Confirm the signing tool path (apksigner from build-tools, or jarsigner from JDK) exists and matches your JDK version","Ensure the unsigned APK input exists and is valid before signing"],"exampleFix":"// before\nsignApk(inputApk, outApk, wrongKeystore, wrongPass, alias)\n// after\nassert new File(keystorePath).exists()\nsignApk(inputApk, outApk, keystorePath, correctStorePassword, keyAlias)","handlingStrategy":"validation","validationCode":"assert new File(keystorePath).exists() : 'keystore missing'\nassert signingTool != null && new File(signingTool).exists() : 'apksigner/jarsigner not found'\nassert storePassword && keyAlias && keyPassword : 'signing credentials incomplete'","typeGuard":null,"tryCatchPattern":"try {\n    ApkUtil.signApk(inputApk, outputApk, keystore, pass, alias)\n} catch (GradleException e) {\n    logger.error('APK signing failed; verify keystore credentials and signing tool path', e)\n    throw e\n}","preventionTips":["Keep signing credentials in gradle.properties / CI secrets, never hardcoded","Pre-validate keystore with keytool -list before building","Match apksigner version to your Android build-tools version"],"tags":["gradle-plugin","apk-signing","external-process","keystore"],"backgroundTag":"api-request-failed","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}