本文介绍了注射用匕首2只依赖于产品的口味之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序由两个产品口味:自由和亲。我有一个 ApplicationModule ,它提供广告的对象,但这个目标只能通过免费版必需的,亲版本没有的 COM .google.android.gms:播放服务的广告:8.3.0 依赖。如何构建我的项目,这样只有当免费产品风味是使用 ApplicationModule 提供的广告对象?

My application consists of two product flavors: free and pro. I have an ApplicationModule that provides the object for ads, but this object is only required by the free version, as the pro version does not have the com.google.android.gms:play-services-ads:8.3.0 dependency. How do I structure my project such that only if the free product flavor is in use the ApplicationModule provides the ads object?

推荐答案

既然你有两个产品的口味,我假设的免费版本类都在正确的版本结构,主资源集之外。和IM假设你有付费版本另一个资源集。

Since you have two product flavors, i am assuming the free version classes are in the proper version structure, outside of the 'main' resource set. and im assuming you have another resource set for paid version.

所以,初始化主要来源集里面的匕首组成部分,但有ApplicationModule驻留在每个风味源集。该模块是供应商,所以如果你想改变依赖你就可以通过定义不同的供应商,即使这两个来源套(付费,nonpaid)将在每个相同的ApplicationModule。

So, initialize the dagger component inside main source set, but have ApplicationModule reside in each flavors source set. The module is the provider, so if you want to change the dependencies you'll be able to by defining different providers even though both source sets (paid ,nonpaid) will have the same ApplicationModule in each.

这篇关于注射用匕首2只依赖于产品的口味之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 13:43
查看更多