使用 Gradle7.2和這些插件:
plugins {
id 'com.android.library' // Android Gradle Plugin 7.1.2
id 'maven-publish'
}
它仍然有效,但給了我這個棄用警告:
警告:不會為從 Android Gradle 插件 8.0 發布的 Maven 自動創建軟體組件。要選擇未來的行為,請
android.disableAutomaticComponentCreation=true在gradle.properties檔案中設定 Gradle 屬性或使用新的發布 DSL。
發行說明也提到了它,但這些是指過時的檔案:
從 AGP 8.0 開始,默認情況下會禁用自動組件創建。目前,AGP 7.1 自動為每個構建變體創建一個與構建變體同名的組件,以及一個包含所有構建變體的 all 組件。此自動組件創建將被禁用。要過渡到新行為,您應該通過設定
android.disableAutomaticComponentCreation為 來手動禁用自動組件創建true。
有關更多資訊,請參閱使用 Maven 發布插件。
但是在檔案中啟用 AGP 8.0 默認行為的預覽時gradle.properties:
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.
違規行內容如下:
release(MavenPublication) {
from components.release
}
變體仍然存在,但它不再創建組件:
androidComponents {
onVariants(selector().all(), {
println "$it.name"
})
}
如何升級到這個“新發布 DSL”并創建要發布的軟體組件?
uj5u.com熱心網友回復:
根據PublishingOptions,必須定義一個android.publishing塊:
android {
publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
// ...
}
}
一次定義多個變體:
android {
publishing {
multipleVariants {
withSourcesJar()
withJavadocJar()
allVariants()
}
}
}
然后例如。components.getByName('release')將再次為人所知。
uj5u.com熱心網友回復:
Android Studio 團隊剛剛在https://developer.android.com/studio/publish-library/configure-pub-variants發布了一些有用的用戶檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/441971.html
標籤:安卓 毕业典礼 android-gradle-插件 maven-发布 android-gradle-7.0
上一篇:當我將手機更新到Android12時,安裝沒有成功。無法安裝應用程式:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
