10

When i sync project, android studio warn could not get unknown property 'bundleRelease' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.

I add project.afterEvaluate{//block},but it doesn't work. What should i do to set the artifact

neuyuandaima
  • 403
  • 1
  • 5
  • 13

2 Answers2

32

Android Gradle Plugin 3.3.x (at least -alpha releases at the time of writing this answer) has breaking change, task bundleRelease was renamed to bundleReleaseAar

So the solution is to use: bundleReleaseAar instead of bundleRelease.

Note: "release" in the task name is buildType/flavor combination, thus it might be different in your setup.


Generic answer: bundleRelease is a task, to find its new name you can run ./gradlew tasks --all

Artem Zinnatullin
  • 4,305
  • 1
  • 29
  • 43
  • 2
    This also applies to the newly stable Android Gradle Plugin 3.2.0. – Venator85 Sep 25 '18 at 10:01
  • 1
    Now at `com.android.tools.build:gradle:3.4.0` the same issue for `artifact bundleReleaseAar`, what to use instead of `bundleReleaseAar`? – NickUnuchek Apr 18 '19 at 06:29
  • 2
    @NickUnuchek It seems we must wrap the whole ```publishing {...}``` block into ```project.afterEvaluate { publishing { ... } }```, then it works. – Robyer Apr 23 '19 at 19:30
22

So the answer from Artem Zunnatullin is correct. Just one addition, the project.afterEvaluate{//block} is necessary to make it work. This information can be overlooked very easily.

Complete example:

project.afterEvaluate {
    publishing {
        publications {
            mavenDebugAAR(MavenPublication) {
                artifact bundleDebugAar

                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.api.allDependencies.each { ModuleDependency dp ->
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dp.group)
                        dependencyNode.appendNode('artifactId', dp.name)
                        dependencyNode.appendNode('version', dp.version)

                        if (dp.excludeRules.size() > 0) {
                            def exclusions = dependencyNode.appendNode('exclusions')
                            dp.excludeRules.each { ExcludeRule ex ->
                                def exclusion = exclusions.appendNode('exclusion')
                                exclusion.appendNode('groupId', ex.group)
                                exclusion.appendNode('artifactId', ex.module)
                            }
                        }
                    }
                }
            }

            mavenReleaseAAR(MavenPublication) {
                artifact bundleReleaseAar

                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    configurations.api.allDependencies.each { ModuleDependency dp ->
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dp.group)
                        dependencyNode.appendNode('artifactId', dp.name)
                        dependencyNode.appendNode('version', dp.version)

                        if (dp.excludeRules.size() > 0) {
                            def exclusions = dependencyNode.appendNode('exclusions')
                            dp.excludeRules.each { ExcludeRule ex ->
                                def exclusion = exclusions.appendNode('exclusion')
                                exclusion.appendNode('groupId', ex.group)
                                exclusion.appendNode('artifactId', ex.module)
                            }
                        }
                    }
                }
            }
        }

        repositories {

            maven {
                name 'nexusSnapshot'
                credentials {
                    username '<User with deployment rights>'
                    password '<User password>'
                }
                url '<URL to nexus>'
            }

            maven {
                name 'nexusRelease'
                credentials {
                    username '<User with deployment rights>'
                    password '<User password>'
                }
                url '<URL to nexus>'
            }
        }
    }
}
JJD
  • 50,076
  • 60
  • 203
  • 339
Satarus
  • 220
  • 2
  • 4