gpt4 book ai didi

android - 将 productFlavor 添加到实验性 Android gradle 插件库

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:25:43 24 4
gpt4 key购买 nike

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

fix似乎不适用于实验性 gradle 插件。有谁知道如何使用新插件制作 flavor ?

图书馆:

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

项目:

...

dependencies {
compile project(':mylibrary')
}

最佳答案

这可能有帮助?

Library Publication

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" }

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 } 

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 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')
}

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.

来自 here .

关于android - 将 productFlavor 添加到实验性 Android gradle 插件库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957274/

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