为什么生成类型从产品风味独特?风味、独特、类型、产品

2023-09-04 10:01:16 作者:奈何桥上等你

preface:这不是一个关于如何使用生成类型和产品口味在一个Android应用程序的问题。我了解所涉及的基本概念。这个问题更多的是想了解哪些配置应在构建类型,它的配置应该在产品风味指定中指定,而任何区别是否真的有必要的。的

这个星期,我一直在学习更多关于Android应用摇篮配置。我最初以为我对构建类型VS产品口味的良好的手感,但更深层次的我坐进文档我越意识到区分两者之间并没有明确的,我在所有。

This week, I've been learning more about gradle configuration for Android apps. I initially thought I had a good handle on build types vs product flavors, but the deeper I got into the documentation the more I realized the distinction between the two was not clear to me at all.

既然有一个明确的层次结构(在这个意义上,在构建类型指定的属性采取precedence对这些产品的口味指定的),我不明白为什么有必要构建类型和区分产品味道都没有。这岂不是更好地合并所有属性和方法到产品的风味DSL的对象,然后只把生成类型为(默认)风味尺寸?

Since there is a well-defined hierarchy (in the sense that properties specified in build types take precedence over those specified in product flavors), I don't understand why there is a need to distinguish between build types and product flavors at all. Would it not be better to merge all properties and methods into the product flavor DSL object, and then just treat build type as a (default) flavor dimension?

这导致了我的困惑一些具体的例子:

Some concrete examples that led to my confusion:

signingConfig 属性可以在这两种类型的建设和产品的口味......来设置,但 minifyEnabled (而且,我认为, shrinkResources ?)只能在构建类型进行配置。

The signingConfig property can be set in both build types and product flavors... but minifyEnabled (and, I assume, shrinkResources?) can only be configured in build types.

的applicationID 只能在产品口味指定...和 applicationIdSuffix 只能在指定生成类型!?

applicationId can only be specified in product flavors... and applicationIdSuffix can only be specified in build types!?

的实际问题(S)

鉴于上面的例子:有没有生成类型的角色之间有着明显的区别VS产品口味

Given the above examples: is there a clear distinction between the roles of build types vs product flavors?

如果是这样,什么是理解它的最佳方法是什么?

If so, what is the best way to understand it?

如果没有,是最终合并生成类型和产品口味成一个可配置的DSL对象的计划?

If not, is the plan to eventually merge build types and product flavors into a single configurable DSL object?

推荐答案

扩展在什么@CommonsWare在评论中说,其基本思路是,建立类型是不同的构建应用程序的不属于功能不同 - 如果你有一个调试和你的应用程序的发布版本,它们是相同的应用程序,而是一个包含调试code,也许更多的日志等,另一种是精简和优化,并通过ProGuard的可能混淆。与调味剂,其意图是,该应用程序是在某些方面明显不同。最明显的例子是一个免费与您的应用程序的付费版本,但开发商也可能区分基于它正在被分发(这可能会影响在应用内计费API的使用)。

Expanding on what @CommonsWare said in the comments, the basic idea is that build types are for different builds of your application that aren't functionally different -- if you have a debug and release version of your app, they're the same app, but one contains debugging code, maybe more logging, etc., and the other is streamlined and optimized and possibly obfuscated via ProGuard. With flavors, the intent is that the app is notably different in some way. The clearest example would be a free vs. a paid version of your app, but developers may also differentiate based on where it's being distributed (which could affect in-app billing API use).

有开发人员,使许多,许多不同版本的类似的应用程序为不同的客户 - 一个例子可能是一个简单的应用程序打开了一个网页,在网页视图,为每个版本不同的URL和品牌 - 这是一款很好用的味道。

There are developers that make many, many different versions of a similar app for different customers -- an example might be a simple app that opens up a web page in a web view, with different URLs and branding for each version -- this is a good use of flavors.

要重申的是,如果它是相同的应用,模一些差异并不重要给最终用户,特别是如果所有除了一个变体是用于自己的测试和开发利用,只有一个变体将被部署到最终用户,那么它是一个很好的候选人构建类型。如果是不同的应用程序和多个变种将被部署到用户,那么也许这是对产品风味的候选者。

To reiterate, if it's "the same application", modulo some differences that aren't important to the end user, and especially if all of the variants except for one are for your own testing and development use and only one variant will be deployed to end users, then it's a good candidate for build types. If it's "a different" application and multiple variants would be deployed to users, then perhaps it's a candidate for a product flavor.

您已经看到,有支持一个构建类型和口味之间的一些功能差异,某些选项而不是其他。但其概念是,即使它们是相似的不同,而且也没有计划将它们合并在一起。

You've already seen that there are some functionality differences between build types and flavors, in that some options are supported for one but not the other. But the concepts are different even though they're similar, and there's no plan to merge them together.