{"record":{"id":"6da6448cc18b87d0","repo":"Tencent/tinker","slug":"publishing-android-library-require-release-varia","errorCode":null,"errorMessage":"Publishing Android library require \"release\" variant","messagePattern":"Publishing Android library require \"release\" variant","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"gradle/WeChatPublish.gradle","lineNumber":580,"sourceCode":"                            }\n                        }\n                    }\n                }\n            }\n\n            pomClosures.each { cl ->\n                project.publishing.publications {\n                    \"${publicationName}${cFlavorName}\"(MavenPublication) {\n                        pom cl\n                    }\n                }\n            }\n        } // android.libraryVariants.all\n\n        // Check whether \"release\" variant is published\n        project.afterEvaluate {\n            if (!hasReleaseVariant)\n                throw new GradleException('Publishing Android library require \"release\" variant')\n        }\n    }\n}\n","sourceCodeStart":562,"sourceCodeEnd":584,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/gradle/WeChatPublish.gradle#L562-L584","documentation":"Thrown from a project.afterEvaluate block in gradle/WeChatPublish.gradle (line 580) after the Android library's libraryVariants have been enumerated. The publish logic iterates project.android.libraryVariants.all and records whether a 'release' variant was seen (hasReleaseVariant); only the release variant is wired into MavenPublication/pom closures. If no variant named 'release' exists at evaluation time, publishing would silently produce nothing, so the script fails fast with this exception.","triggerScenarios":"Applying wechatPublish to a com.android.library module whose variants exclude release: (a) variantFilter/android.buildTypes removes or renames the release buildType; (b) buildTypes only defines debug; (c) a build system (e.g. some component-based or plugin frameworks like some Atlas/Robolectric-injected setups) mutates libraryVariants before afterEvaluate; (d) the release variant is created only later by another plugin's afterEvaluate, so this block runs first and still sees it missing.","commonSituations":"Publishing an Android library that intentionally ships only debug for local dev; renaming buildTypes (e.g. 'release' -> 'online') for channel flavors; variantFilter { setIgnore true } on release; ordering conflicts between wechatPublish's afterEvaluate and another plugin that adds or removes variants.","solutions":["Ensure the module has a standard release buildType: android { buildTypes { release { ... } } } and that no variantFilter ignores it.","Remove any 'setIgnore true' for release variants in your variantFilter block.","If release was renamed, keep a release buildType and add your extra channels as product flavors or additional buildTypes instead of renaming release.","If another plugin's afterEvaluate must create the variant first, apply that plugin before this publish script so its afterEvaluate callback registers earlier."],"exampleFix":"// before\nandroid {\n    variantFilter { variant ->\n        if (variant.buildType.name == 'release') variant.setIgnore(true)\n    }\n}\n\n// after\nandroid {\n    buildTypes {\n        release {\n            minifyEnabled false\n        }\n    }\n}","handlingStrategy":"validation","validationCode":"// quick check before running publish tasks\n// (Groovy) confirm the library exposes a release variant\nafterEvaluate {\n    def names = android.libraryVariants.collect { it.name }\n    assert names.contains('release') : \"no release variant: ${names}\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a standard release buildType in every published library module.","Never setIgnore(true) the release variant in variantFilter.","Apply plugins that create/remove variants before the publish script so afterEvaluate ordering is deterministic."],"tags":["gradle","android","publishing","build-variants","configuration"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}