android - 用于仅测试依赖项的 Gradle 变体感知依赖项管理
问题描述
我有一个多模块 Android 项目,其中包含一个仅用于测试的模块testImplementation project(path: 'libtestsupport')
。除非我通过 为非测试构建包含此模块,否则自动变体切换似乎不起作用,implementation project(path: 'libtestsupport')
我不想这样做,因为它只被测试使用。这导致此库模块的构建变体与其他模块不匹配:
有没有办法让这个库依赖项像应用程序中的其他依赖项一样自动切换构建变体?
解决方案
如何解决:解决与依赖匹配相关的构建错误
构建错误的原因:
您的应用程序包含库依赖项不包含的构建类型。
例如,您的应用程序包含“暂存”构建类型,但依赖项仅包含“调试”和“发布”构建类型。
请注意,当库依赖项包含您的应用程序不包含的构建类型时,没有问题。那是因为插件根本不会从依赖项中请求该构建类型。
解析度
使用 matchingFallbacks 为给定的构建类型指定替代匹配,如下所示:
// In the app's build.gradle file.
android {
buildTypes {
debug {}
release {}
staging {
// Specifies a sorted list of fallback build types that the
// plugin should try to use when a dependency does not include a
// "staging" build type. You may specify as many fallbacks as you
// like, and the plugin selects the first build type that's
// available in the dependency.
matchingFallbacks = ['debug', 'qa', 'release']
}
}
}
推荐阅读
- encoding - Arduino 中编码器的 X1、X2、X4 编码
- r - 使用 for 循环 R 中的列表以 rbind 元素(如果存在)
- python - 如何将 rgb 图像转换为 cmyk?
- jquery - 在jQuery中获取字符符号的HTML实体
- python - 在不知道它们的值的情况下对 Python 数字列表进行排序,而只知道它们之间的关系
- javascript - 扩展不从 integration.json 加载文件
- spring-boot - CriteriaBuilder OffsetDateTime 比较
- swift - CollectionView 上的多个数组值 - Swift
- ruby-on-rails - 切换到 Zeitwerk 时出现未初始化的常量错误
- python - 如何从另一个 .py 文件访问 main.py 中的类?