将productFlavor添加到实验性Android Gradle插件库 [英] Add productFlavor to experimental Android gradle plugin library

查看:227
本文介绍了将productFlavor添加到实验性Android Gradle插件库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用实验性gradle插件的项目,即0.2.0.当我没有productFlavor时,我可以完美地将库模块集成到Android Studio中,并且一切正常.但是当库具有productFlavor时,我的主项目找不到库类.

I've got a project that uses the experimental gradle plugin, i.e. 0.2.0. When I've got no productFlavor, I can perfectly integrate a library module in Android Studio and everything works perfectly. But when the library has a productFlavor, I main project doesn't find the library classes.

修复确实可以似乎不适用于实验性Gradle插件.有谁知道如何使风味与新插件兼容?

This fix does not appear to work with the experimental gradle plugin. Does anyone have any idea how make flavors work with the new plugin?

图书馆:

android.productFlavor {
    create ('flavor') {
        ...
    }
}

项目:

...

dependencies {
    compile project(':mylibrary')
}

推荐答案

这可能有帮助吗?

图书馆出版物

默认情况下,库仅发布其发行版本.这个变体 无论引用哪个库,所有引用该库的项目都将使用它 他们建立自己的变体.这是由于以下原因造成的暂时性限制 我们正在努力消除的Gradle限制.

By default a library only publishes its release variant. This variant will be used by all projects referencing the library, no matter which variant they build themselves. This is a temporary limitation due to Gradle limitations that we are working towards removing.

您可以控制使用哪个变体发布

You can control which variant gets published with

android { defaultPublishConfig "debug" }

请注意,此发布配置名称引用了完整的名称 变体名称.仅当没有发布和调试时,才适用 口味.如果您想更改默认的已发布变体 使用调味剂,您将编写:

Note that this publishing configuration name references the full variant name. Release and debug are only applicable when there are no flavors. If you wanted to change the default published variant while using flavors, you would write:

android {defaultPublishConfig "flavor1Debug" }

还可以发布库的所有变体.我们是 计划在使用常规项目间项目时允许这样做 依赖关系(如上图所示),但是由于当前原因,这是不可能的 限制Gradle中的限制(我们也在努力解决这些问题). 默认情况下,不启用所有变体的发布.要启用它们:

It is also possible to publish all variants of a library. We are planning to allow this while using a normal project-to-project dependency (like shown above), but this is not possible right now due to limitations in Gradle (we are working toward fixing those as well). Publishing of all variants are not enabled by default. To enable them:

android {publishNonDefault true } 

重要的是要意识到发布多个变体意味着 发布多个aar文件,而不是包含一个的aar文件 多种变体.每个aar包装都包含一个变体. 发布变体意味着将此aar用作输出 Gradle项目的工件.然后可以在以下情况下使用 发布到Maven存储库,或当另一个项目创建一个 对图书馆项目的依赖.

It is important to realize that publishing multiple variants means publishing multiple aar files, instead of a single aar containing multiple variants. Each aar packaging contains a single variant. Publishing a variant means making this aar available as an output artifact of the Gradle project. This can then be used either when publishing to a maven repository, or when another project creates a dependency on the library project.

Gradle具有默认概念"构件.这就是 编写时使用:

Gradle has a concept of default" artifact. This is the one that is used when writing:

compile project(':libraries:lib2')

要创建对另一个已发布工件的依赖关系,您需要 指定要使用哪个:

To create a dependency on another published artifact, you need to specify which one to use:

dependencies {
    flavor1Compile project(path: ':lib1', configuration: 'flavor1Release')
    flavor2Compile project(path: ':lib1', configuration: 'flavor2Release') 
}

重要提示:请注意,已发布的配置是完整版本, 包括构建类型,并且需要这样引用. 重要提示:启用非默认发布时,Maven 发布插件将发布这些额外的变体 包(带有分类器).这意味着这不是真的 与发布到Maven存储库兼容.你应该 将单个变体发布到存储库或启用所有配置 发布项目间的依赖关系.

Important: Note that the published configuration is a full variant, including the build type, and needs to be referenced as such. Important: When enabling publishing of non-default, the Maven publishing plugin will publish these additional variants as extra packages (with classifier). This means that this is not really compatible with publishing to a maven repository. You should either publish a single variant to a repository OR enable all config publishing for inter-project dependencies.

来自此处.

这篇关于将productFlavor添加到实验性Android Gradle插件库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆