gpt4 book ai didi

android - 不会为从 Android Gradle 插件 8.0 发布的 Maven 自动创建软件组件

转载 作者:行者123 更新时间:2023-12-04 23:42:08 34 4
gpt4 key购买 nike

使用 Gradle 7.2和这些插件:

plugins {
id 'com.android.library' // Android Gradle Plugin 7.1.2
id 'maven-publish'
}
它仍然有效,但给了我这个弃用警告:

WARNING: Software Components will not 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.


还有 release notes提到它,但这些指的是过时的文档:

Starting AGP 8.0, automatic component creation will be disabled by default. Currently, AGP 7.1 automatically creates a component for each build variant, which has the same name as the build variant, and an an all component that contains all the build variants. This automatic component creation will be disabled. To transition to the new behavior, you should manually disable automatic component creation by setting android.disableAutomaticComponentCreation to true.
For more information, see Use the Maven Publish plugin.



但是在文件 gradle.properties 中启用 AGP 8.0 默认行为的预览时:
android.disableAutomaticComponentCreation=true
它找不到属性 components.release :
FAILURE: Build failed with an exception.

* Where:
Script 'publish.gradle' line: 53

* What went wrong:
A problem occurred configuring project ':library'.
> Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
offending line阅读:
release(MavenPublication) {
from components.release
}
变体仍然存在,但它不再创建组件:
androidComponents {
onVariants(selector().all(), {
println "$it.name"
})
}
如何升级到这个“新发布 DSL”并创建软件 component发布?

最佳答案

根据 PublishingOptions ,必须定义一个 android.publishing堵塞:

android {
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
// ...
}
}
一次定义多个变体:
android {
publishing {
multipleVariants {
withSourcesJar()
withJavadocJar()
allVariants()
}
}
}
然后例如。 components.getByName('release')将再次为人所知。

关于android - 不会为从 Android Gradle 插件 8.0 发布的 Maven 自动创建软件组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71365373/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com