Android的自定义工作流产品的香精 [英] Android Customize Workflow for Product Flavors

查看:218
本文介绍了Android的自定义工作流产品的香精的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆产品的口味这是基本上是一个单一的应用程序的白色标签的应用程序。然而,过一段时间,有一个从一些味道,因为客户想要的东西稍有不同的主流程存在一些分歧。
到目前为止,我们一直在编辑code的情形外,用面条code(IFS地段和别人的),以确保其他应用程序不破。不用说,这是不是要做到这一点非常可扩展的(甚至是理智的)的方式。

I have an app with a bunch of product flavors which are basically white labels of a single app. However, once in a while, there is some divergence from the main flow in some flavor because the client wants something slightly different. So far, we have been editing the code for those cases and using spaghetti code (lots of ifs and elses) to make sure the other apps don't break. Needless to say this isn't a very scalable (or even sane) way to do this.

一种选择是写在productFlavor源文件夹中的活动课,即的src / flavor1 / JAVA / AnActivity.java 的src / flavor2 /java/AnActivity.java 等。
由于productFlavor code不能覆盖的src / main 类,这将需要被复制为每个新的口味,即使没有定制相同的类。我真的不喜欢这个选项了。它导致了很多冗余code和类名最终被没有这么描述的了,因为他们都必须有以覆盖别人,即使他们可能会做一些不同的相同的名称。

One option would be to write the activity classes in the productFlavor source folders i.e. src/flavor1/java/AnActivity.java, src/flavor2/java/AnActivity.java, etc. Since productFlavor code can't override the src/mainclasses, this would require the same classes to be copied over for each new flavor even if there is not customization. I don't really like this option much. It results in a lot of redundant code and class names end up being not so descriptive anymore since they all have to have the same names in order to override others even though they might be doing something different.

另一个选择可能是使用像匕首来构建一个 ObjectGraph 和不同的实现注入意图。例如,如果是 flavor1 ,按钮被点击×表示,对于一个意图 ActivityA 注入,如果它 flavor2 ,对于意图 ActivityB 注入。

Another option could be to use something like Dagger to build an ObjectGraph and inject Intents for different implementations. For example, if it's flavor1, when button X is clicked, an intent for ActivityA is injected and if it's flavor2, an intent for ActivityB is injected.

这似乎是一个更好的办法做到这一点,但我仍然不知道如何实现,将覆盖绑定默认类 ObjectGraph

This seems like a better way to do this but I'm still not sure how to implement classes that would override bindings in the default ObjectGraph.

在实现或其他选项的任何想法?我不绑定到匕首,我刚开始寻找到依赖注入和测试,以便其他框架很好的工作。

Any ideas on implementations or other options? I'm not bound to Dagger, I'm just starting to look into dependency injection and testing so other frameworks work just as well.

推荐答案

下面是我做的...

的src / flavor1 / JAVA / COM / MyApp的/ Modules.java

public class Modules {
  public static Object[] get(Application app) {
    return new Object[] {
      new MyAppModule(app),
      new Flavor1Module(app)
    };
  }
}

的src / flavor2 / JAVA / COM / MyApp的/ Modules.java

public class Modules {
  public static Object[] get(Application app) {
    return new Object[] {
      new MyAppModule(app),
      new Flavor2Module(app)
    };
  }
}

的src / main / JAVA / COM / MyApp的/ MyAppApplication.java

ObjectGraph og = ObjectGraph.create(Modules.get(this));

MyAppModule 有共同的依赖。 Flavor1Module Flavor2Module 可以促进更多的相关性或从 MyAppModule 如果覆盖=真

MyAppModule has common dependencies. Flavor1Module and Flavor2Module can contribute additional dependencies or override ones from MyAppModule if overrides=true.

这篇关于Android的自定义工作流产品的香精的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆