何时使用 android 风格与单独的项目

when to use android flavours vs separate projects

我一直在阅读 Android 风格以及如何在 SO 和其他资源(例如

中使用它们

1)Building Multiple Editions of an Android App with Gradle

2)Building multiple flavours of an Android app

根据这些示例,android flavours 对于构建应用程序的多个版本非常有用。但我的问题是:

service providerconsumer 角色有单独的应用程序如 uber 的场景中使用 flavor 是一个好习惯,还是构建单独的项目更好。

在使用风味之前我们需要考虑的主要属性是什么?

创建多个环境不同于单独的应用程序。

我认为,最佳做法是为每个单独的应用程序创建多个环境。

例如,对于许多项目,他们有 2 个应用程序,一个供用户使用,另一个供管理员使用。所以在那种情况下,我们为每个应用程序创建 4 个环境。

构建多个环境将最大限度地提高生产力并减少可能影响用户的错误。有 4 个常用层级可以提供帮助

Development Optional. This is the working environment for individual developers or small teams. Working in isolation with the rest of the tiers, the developer(s) can try radical changes to the code without adversely affecting the rest of the development team.

Integration A common environment where all developers commit code changes. The goal of this environment is to combine and validate the work of the entire project team so it can be tested before being promoted to the Staging Environment. It is possible for Development and Integration to be the same environment (as in the case where the developer does not use a local copy of the source code).

Staging The staging tier is a environment that is as identical to the production environment as possible. The purpose of the Staging environment is to simulate as much of the Production environment as possible. The Staging environment can also double as a Demonstration/Training environment.

Production The production tier might include a single machine or a huge cluster comprising many machines.

一个非常常见的用例,您可以在 Development 环境中删除、编辑任何您想要的东西,但不能在 Production,唯一的办法就是迁移数据。

幸运的是,Android Gradle 支持 productFlavors 支持我们。

但是,是的,如果你只需要一个管理应用程序环境,它接受经常发生的错误,你可以只定义一个环境。

这是一个很大的话题,也许这个答案可以帮助到你。这是多个环境的通用流程

来自 Android docs:

Product flavors represent different versions of your app that you may release to users, such as free and paid versions of your app. You can customize product flavors to use different code and resources, while sharing and reusing the parts that are common to all versions of your app.

因此,应使用产品风味来创建同一应用的自定义版本。不同的风格可能在某些资源和功能上有所不同,但它们几乎是同一个应用程序。

为了构建彼此相关并共享部分代码的不同应用程序,最好使用模块。您将拥有 2 个用于应用程序的应用程序模块和一个包含公共代码部分的库模块。应用程序模块将依赖于库模块。