{"record":{"id":"4e92efb4e18bde26","repo":"Tencent/matrix","slug":"process-errorstream-bufferedreader-readlines-j","errorCode":null,"errorMessage":"process.errorStream.bufferedReader().readLines().joinTo(StringBuilder(), \"\\n\").toString()","messagePattern":"process\\.errorStream\\.bufferedReader\\(\\)\\.readLines\\(\\)\\.joinTo\\(StringBuilder\\(\\), \"\\\\n\"\\)\\.toString\\(\\)","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-gradle-plugin/src/main/kotlin/com/tencent/matrix/plugin/task/RemoveUnusedResourcesTask.kt","lineNumber":240,"sourceCode":"                    }\n                }\n\n                zipOutputStream.close()\n\n                Log.i(TAG, \"shrink apk size %f KB\", (inputFile.length() - outputFile.length()) / 1024.0)\n                if (needSign) {\n                    Log.i(TAG, \"Sign apk...\")\n                    val processBuilder = ProcessBuilder()\n                    processBuilder.command(apksigner, \"sign\", \"-v\",\n                            \"--ks\", signingConfig!!.storeFile?.absolutePath,\n                            \"--ks-pass\", \"pass:\" + signingConfig.storePassword,\n                            \"--key-pass\", \"pass:\" + signingConfig.keyPassword,\n                            \"--ks-key-alias\", signingConfig.keyAlias,\n                            outputFile.absolutePath)\n                    val process = processBuilder.start()\n                    process.waitFor()\n                    if (process.exitValue() != 0) {\n                        throw GradleException(process.errorStream.bufferedReader().readLines()\n                                .joinTo(StringBuilder(), \"\\n\").toString())\n                    }\n                }\n                val backApk = inputFile.parentFile.absolutePath + \"/\" + inputFile.name.substring(0, inputFile.name.indexOf('.')) + \"_back.apk\"\n                inputFile.renameTo(File(backApk))\n                outputFile.renameTo(File(originalApk))\n\n                //modify R.txt to delete the removed resources\n                if (removeResources.isNotEmpty()) {\n                    val styleableItera = styleableMap.keys.iterator()\n                    while (styleableItera.hasNext()) {\n                        val styleable = styleableItera.next()\n                        val attrs = styleableMap[styleable]\n                        var j = 0\n                        for (i in 0 until (attrs!!.size)) {\n                            j = i\n                            if (!removeResources.containsValue(attrs[i].right)) {\n                                break","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-gradle-plugin/src/main/kotlin/com/tencent/matrix/plugin/task/RemoveUnusedResourcesTask.kt#L222-L258","documentation":"After rebuilding and re-signing the APK, the task runs apksigner as an external process; if apksigner exits with a non-zero exit code, the task throws a GradleException whose message is the entire stderr of that process. This message therefore echoes whatever apksigner reported (e.g. keystore errors, bad passwords, unsupported signature algorithms).","triggerScenarios":"apksigner invocation in `removeUnusedResources` fails: wrong keystore password, wrong key alias/password, corrupted or incompatible keystore, or apksigner rejecting the unsigned APK — detected via `process.exitValue() != 0`.","commonSituations":"Stale or wrong `keyPassword`/`keyAlias` in signingConfig; keystore generated with an algorithm the build-tools' apksigner cannot read; min/target SDK requiring v2 signatures with an old build-tools version; quoting issues in the pass arguments.","solutions":["Read the captured stderr in the exception message — it contains apksigner's own diagnosis; fix the underlying signing issue it names.","Verify keystore password, key alias and key password are correct (`keytool -list -keystore ...` or `apksigner sign --ks ...` manually).","Upgrade Android build-tools to a recent version so apksigner matches the APK's minSdk/v1-v4 signature requirements.","Sign the shrunk APK manually with apksigner outside Gradle if automated signing keeps failing."],"exampleFix":"// before (wrong password in signingConfig)\nsigningConfigs { release { keyPassword \"wrongpass\" } }\n\n// after\nsigningConfigs { release { keyPassword System.getenv(\"KEY_PASSWORD\") } }","handlingStrategy":"try-catch","validationCode":"def proc = [apksigner, 'sign', '--ks', ksFile, '--ks-key-alias', alias, '--ks-pass', 'pass:' + ksPass, '--key-pass', 'pass:' + keyPass, apk].execute()\nproc.waitFor()\nassert proc.exitValue() == 0 : proc.errorStream.text","typeGuard":null,"tryCatchPattern":"try { removeUnusedResourcesTask.execute() } catch (GradleException e) { logger.error('apksigner failed: ' + e.message); throw e }","preventionTips":["Test signing manually with apksigner before wiring it into Gradle.","Store passwords via environment variables/gradle.properties to avoid stale hard-coded values.","Keep build-tools updated to match APK signature-scheme requirements."],"tags":["gradle","android","signing","process-failure","apksigner"],"backgroundTag":"http-error-response","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"}