提问人:dilix 提问时间:11/14/2019 最后编辑:dilix 更新时间:11/14/2019 访问量:114
没有来自多风格库主要来源的类
No classes from main sources from multi flavor library
问:
我有一个有 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
对于其中一种风格,我在里面有自定义布局:
所有其他来源都应来自 。main
当我将此库包含到应用程序时:
implementation project(path: ':sdk', configuration: 'internalDebug')
根本没有库的类,所有导入都标记为红色。sdk
问题是为什么应用程序中没有来自库文件夹的源代码?main
答:
1赞
dilix
11/14/2019
#1
最后,我得到了解决方案,如在应用程序中定义的那样。missingDimensionStrategy
build.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 将找到一个依赖项,该依赖项应该用于此。flavorDimension
outerInner
internal
应用后,我可以简单地包括
implementation project(path: ':sdk')
对于每个应用的 buildType,它将使用适当的 SDK build 并回退到实现。debug
relese
internal
External
实现通过设置交付给 Maven。artifact bundleExternalDebugAar
评论
0赞
JCarlosR
8/16/2022
谢谢。这对于添加对项目的依赖关系很有用,而无需像在库中那样定义风格。missingDimensionStrategy 'your_dimension', 'your_default_flavor'
评论
publishNonDefault true
android {}