Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

maven-publish cannot find the release component of an Android library

ErrorCould not get unknown property 'release' for SoftwareComponentInternal

Short 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.

  • Applies to Android Gradle Plugin 8.x, Gradle 8.x, maven-publish plugin
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/null
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2afterEvaluate is already in place, but the same error appears, and the android block has no publishing sectionThe release variant was never declared for publishingFix

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/null

2Fix

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:publishReleasePublicationToMavenLocal

Confirmed by developer.android.com

Did this fix it?

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/null

2Fix

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:publishReleasePublicationToMavenLocal

Confirmed by developer.android.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.