问题描述
我在 Android Studio 3.2 上使用 Gradle 4.1 和 Gradle-Android 插件 3.0.1
I am using Gradle 4.1 with Gradle-Android plugin 3.0.1 on Android Studio 3.2
我有生产"和暂存"两种风格,我无法将我的项目构建为具有不同构建变体的库.
I have 2 flavors 'production' and 'staging' and I am unable to build my project as a library with different build variants.
app build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
...
productFlavors {
production {
}
staging {
}
}
defaultPublishConfig "productionRelease"
publishNonDefault true
}
if( android.productFlavors.size() > 0 ) {
android.libraryVariants.all { variant ->
if( android.publishNonDefault && variant.name == android.defaultPublishConfig ) {
def bundleTask = tasks["bundle${name.capitalize()}"]
artifacts {
archives(bundleTask.archivePath) {
classifier name.replace('-' + variant.name, '')
builtBy bundleTask
name name.replace('-' + variant.name, '')
}
}
}
...
然后我运行:./gradlew clean install,我得到的错误是:
Then I run: ./gradlew clean install, errors I got is:
任务‘:app:install’执行失败.
Execution failed for task ‘:app:install’.
无法发布配置档案"一个 POM 不能有多个具有相同类型和分类器的工件.已经有MavenArtifact app:aar:aar:null,尝试添加MavenArtifact app:aar:aar:null.
为了编译这段代码,我需要将 android.publishNonDefault 与 true 交换,否则我会得到一个错误:Cannot get the value只写属性 'publishNonDefault'
And to get this code to compile, I need to swap android.publishNonDefault with true, otherwise I will get an error of: Cannot get the value of write-only property 'publishNonDefault'
任何建议或提示都会非常有帮助,目的是在 jitpack 上构建库模块,我们可以在其中将其导入到带有构建变体的项目中.谢谢!
Any suggestions or hint would be really helpful, the aim is to build the library module on jitpack, where we can import it in project with build variants. thanks!
推荐答案
在深入研究 2 天并通过电子邮件发送 Jitpack 支持后,问题是因为 lib 已更新并且 publishNonDefault 已弃用.您只需要将您的应用 build.gradle 更改为:
After digging into this for 2 days, and emailing Jitpack support, the issue is because the lib has updated and publishNonDefault is deprecated. you just need to change your app build.gradle to:
apply plugin: 'com.github.dcendents.android-maven'
dependencies {...}
group = 'com.github.your-group'
if (android.productFlavors.size() > 0) {
android.libraryVariants.all { variant ->
if (variant.name.toLowerCase().contains("debug")) {
return
}
def bundleTask = tasks["bundle${variant.name.capitalize()}"]
artifacts {
archives(bundleTask.archivePath) {
classifier variant.flavorName
builtBy bundleTask
name = project.name
}
}
}
}
这篇关于在 Android 中构建多风格的 jitpack 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!