maven-publish cannot find the release component of an Android library
Could not get unknown property 'release' for SoftwareComponentInternalShort answer
With the Android Gradle Plugin, the release software component does not exist when the publishing block is read. It is created later, and only if you ask for it. Declare it with singleVariant("release") in the android block, and select it inside afterEvaluate in the publication.
Fix it fast
1Find out which cause you have
Open the module-level build file of the library and look at the publication. Find the line that reads components.release (or components["release"]), then check whether it sits inside afterEvaluate and whether the android block has a publishing section.
grep -n -E "components|afterEvaluate|singleVariant|multipleVariants" build.gradle build.gradle.kts 2>/dev/null2Match what you see, then jump to its fix
- 1
The build file has from components.release (or from(components["release"])) directly inside the publication, with no afterEvaluate around itThe publication reads the component before AGP has created itFix - 2
afterEvaluate is already in place, but the same error appears, and the android block has no publishing sectionThe release variant was never declared for publishingFix
- 1
What does the error look like?
Could not get unknown property 'release' for SoftwareComponentInternal
Cause 1 of 2
The publication reads the component before AGP has created it
1Check
Android's publishing guide says that with AGP the software components are not created when the plugin is applied. They are created during the afterEvaluate callback, so the publication that selects the component must also be configured there.
grep -n -B3 -A3 "components" build.gradle build.gradle.kts 2>/dev/null2Fix
Wrap the from(...) call in afterEvaluate inside the publication.
// build.gradle.kts of the library module
publishing {
publications {
register<MavenPublication>("release") {
groupId = "com.example"
artifactId = "my-library"
version = "1.0"
afterEvaluate {
from(components["release"])
}
}
}
}3Verify
List the publish tasks, then publish to your local Maven repository.
./gradlew :my-library:tasks --group publishing
./gradlew :my-library:publishReleasePublicationToMavenLocalConfirmed by developer.android.com
Cause 2 of 2
The release variant was never declared for publishing
1Check
Since AGP 7.1, a build variant becomes a software component only when you ask for it in the android { publishing { } } block. The component takes its name from what you give to singleVariant() or multipleVariants().
grep -n -A4 "publishing" build.gradle build.gradle.kts 2>/dev/null2Fix
Declare the release variant in the android block of the library module. If you named it something else, use that same name in components[...].
android {
publishing {
singleVariant("release") {
withSourcesJar()
}
}
}3Verify
Sync, then run the publish task again. The error should be gone.
./gradlew :my-library:publishReleasePublicationToMavenLocalConfirmed by developer.android.com
How do I stop it coming back?
- Keep the android publishing block and the afterEvaluate publication together in the library module, never in the root build file.
- Use the same name in singleVariant(...) and in components[...].
- Publish to the local Maven repository first, and check the result before pushing to a remote one.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Gradle says it could not get unknown property 'android' for the root project
Could not get unknown property 'android' for root project 'android' of type org.gradle.api.Project.
The android block is added by the Android Gradle Plugin, and only to a project where that plugin is applied.
2 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix