Cannot create a Publication named 'android' because this container does not support creating elements by name alone

Viewed 40

I'm using Gradle to publish a number of variants on Artifactory, and following an example I've found online, I've used this code:

 publishing {
     publications {
         android.buildTypes.all { variant ->
             "${variant.name}Aar"(MavenPublication) {
                 artifactId = "artifactory_artifactId-${variant.name}"
                 groupId = "artifactory_groupId"
                 version = "v1.0.0"
                 // Going off of default Gradle naming configurations
                 artifact("$buildDir/outputs/aar/${project.getName()}-${variant.name}.aar")

                 artifact("$buildDir/outputs/aar/${project.getName()}-${variant.name}.aar") {
                     classifier variant.name
                     extension "aar"
                 }
             }
         }
     }
 }

These are my plugins and dependencies:

 dependencies {
     classpath "com.android.tools.build:gradle:7.0.4"
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
     classpath 'com.android.tools.build:gradle:7.2.1'
     classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:latest.release'
 }

When I synchronise my files on Android Studio, in the console the following error is printed:

"Cannot create a Publication named 'android' because this container does not support creating elements by name alone. Please specify which subtype of Publication to create. Known subtypes are: MavenPublication"

I don't understand which import should I make to solve my problem. What should I import of "android"?

I should be able to use the "variant" object in order to publish dynamically the .aar files together without specifying them all separately. If there's an alternative, I'll be happy to use it.

0 Answers
Related