Gradle 8.0发布Android aar时报错解决

Android library要发布到Maven,升级到Gradle 8.0之后报错 Could not get unknown property ‘release’ for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

解决方法

在module的build.gradle的android节点下,添加:

android {
    publishing {
        singleVariant("release") {
            withSourcesJar()
            withJavadocJar()
        }

        multipleVariants {
            withSourcesJar()
            withJavadocJar()
            allVariants()
        }
    }
}

原因

Software Components are be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the gradle.properties file or use the new publishing DSL.

参考文献

https://stackoverflow.com/a/77141507

https://stackoverflow.com/a/71366104

https://developer.android.com/reference/tools/gradle-api/7.1/com/android/build/api/dsl/PublishingOptions

Share

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注