没有来自多风格库主要来源的类

No classes from main sources from multi flavor library

提问人:dilix 提问时间:11/14/2019 最后编辑:dilix 更新时间:11/14/2019 访问量:114

问:

我有一个有 2 种风格的库项目

configurations {
    // Initializes placeholder configurations that the Android plugin can use when targeting
    // the corresponding variant of the app.
    internalDebug {}
    internalRelease {}
    externalDebug {}
    externalRelease {}
}

flavorDimensions("outerInner")
productFlavors {
    internal{dimension "outerInner"}
    external{dimension "outerInner"}
}

build.gradle 中未定义自定义 sourceSet

对于其中一种风格,我在里面有自定义布局:

enter image description here

所有其他来源都应来自 。main

当我将此库包含到应用程序时:

implementation project(path: ':sdk', configuration: 'internalDebug')

根本没有库的类,所有导入都标记为红色。sdk

问题是为什么应用程序中没有来自库文件夹的源代码?main

android-gradle-plugin build.gradle android-productflavors android-flavors

评论

0赞 Jeel Vankhede 11/14/2019
应用模块中有产品口味吗?
0赞 dilix 11/14/2019
@JeelVankhede不,我想这应该不是问题,因为我明确设置了我想使用的配置。
0赞 Jeel Vankhede 11/14/2019
在我的情况下(多风味库 - >具有不同产品口味名称的多风味应用程序),在块中的库 gradle 中尝试一下。publishNonDefault trueandroid {}
0赞 dilix 11/14/2019
@JeelVankhede不,无济于事......你能分享一下你的库和主应用程序的build.gradle吗?
0赞 Jeel Vankhede 11/14/2019
对不起,@dilix,我现在无法共享 Gradle 文件,因为我无法再访问它,但这是我当时提到的对我有帮助的解决方案:stackoverflow.com/a/36828415/10271334。希望对您有所帮助!

答:

1赞 dilix 11/14/2019 #1

最后,我得到了解决方案,如在应用程序中定义的那样。missingDimensionStrategybuild.gradle

// Specifies a sorted list of flavors that the plugin should try to use from
// a given dimension. The following tells the plugin that, when encountering
// a dependency that includes a "minApi" dimension, it should select the
// "minApi18" flavor. You can include additional flavor names to provide a
// sorted list of fallbacks for the dimension.
missingDimensionStrategy 'outerInner', 'internal'

这意味着,如果在构建过程中,gradle 将找到一个依赖项,该依赖项应该用于此。flavorDimensionouterInnerinternal

应用后,我可以简单地包括

implementation project(path: ':sdk')

对于每个应用的 buildType,它将使用适当的 SDK build 并回退到实现。debugreleseinternal

External实现通过设置交付给 Maven。artifact bundleExternalDebugAar

评论

0赞 JCarlosR 8/16/2022
谢谢。这对于添加对项目的依赖关系很有用,而无需像在库中那样定义风格。missingDimensionStrategy 'your_dimension', 'your_default_flavor'