有一个产品的风味是另一个孩子 [英] Have a product flavor be a child of another

查看:162
本文介绍了有一个产品的风味是另一个孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设立了产品的味道在我的应用程序,并遇到了一个问题。我的两个产品的口味非常相似,彼此只相差几个资源,我们姑且称之为FlavorA和FlavorB。我想设置它,以便FlavorA是FlavorB的父母,这样FlavorB可以只覆盖FlavorA的一些资源,然后FlavorA覆盖了一堆资源从主。有没有办法建立一个层次的味道像这样?现在我需要复制大量两者之间的资源,以便为它工作,我想,以消除重复。

编辑:OK。我有一对夫妇的答案为止(包括删除)这是不相关的,我的问题所以让我澄清一下。这不都与Java的面向对象,我已经知道了相当不错的。 :)

我遇到的问题是,我有一个免费/付费版本我的应用程序,然后几个白色的标签,只有包括主题更改。付费版只能从免费版本(除了code的变化)改变了一些资产。这是我的 productFlavors 是这样的:

  productFlavors {
        whiteLabelA {
            的applicationIDcom.whiteLabelA.android
        }

        whiteLabelB {
            的applicationIDcom.whiteLabelB.android
        }

        mainFree {
            的applicationIDcom.mainFree.android
        }

        mainPaid {
            的applicationIDcom.mainFree.android.paid
        }
    }
 

我想 mainPaid 来替代 mainFree ,因为它只是改变了一些资源。我想这样来做,而不是免费/付费版本的类型,因为白色的标签,没有付费版本,它会更容易有一样的味道层次:

  mainPaid延伸mainFree {
    的applicationIDcom.mainFree.android.paid
}
 

解决方案

我想你不会是能够做到这一点,在机器人对象直接,但你可以使用配置的函数,在一番风味设置公共属性。在安卓之后将这个目标:

 无效configureWhiteLabelFlavor(味){
    flavor.useJack =真
}

configureWhiteLabelFlavor(android.productFlavors.whiteLabelA)
 

如果需要,您可以通过呼叫其他功能,从这个功能实现深继承。

I'm setting up the product flavors in my app and have run into one problem. Two of my product flavors are very similar to each other and only differ by a few resources, let's call them FlavorA and FlavorB. I would like to set it up so that FlavorA is the parent of FlavorB, that way FlavorB can just override a few resources of FlavorA, and then FlavorA overrides a bunch of resources from main. Is there a way to set up a flavor hierarchy such as this? Right now I need to duplicate lots of resources between the two in order for it to work and I would like to eliminate that duplication.

edit: OK. I've had a couple answers so far (both deleted) that were not related to my question so let me clarify. This does not have to do with Java OOP, I already know that quite well. :)

The issue I'm having is that I have a free/paid version of my app, and then several white labels that only include theme changes. The paid version only changes a few assets from the free version (apart from code changes). This is what my productFlavors look like:

productFlavors {
        whiteLabelA {
            applicationId "com.whiteLabelA.android"
        }

        whiteLabelB {
            applicationId "com.whiteLabelB.android"
        }

        mainFree {
            applicationId "com.mainFree.android"
        }

        mainPaid {
            applicationId "com.mainFree.android.paid"
        }
    }

I would like mainPaid to override mainFree since it only changes a few resources. I would like to do it this way rather than a free/paid build type because the white labels don't have paid versions, and it would be easier to have a flavor hierarchy like:

mainPaid extends mainFree {
    applicationId "com.mainFree.android.paid"
}

解决方案

I think you won't be able to do this in the android object directly, but you can use a configuration function to set common properties on a flavor. Put this after the android object:

void configureWhiteLabelFlavor(flavor) {
    flavor.useJack = true
}

configureWhiteLabelFlavor(android.productFlavors.whiteLabelA)

If needed, you can implement deep inheritance by calling other functions from this function.

这篇关于有一个产品的风味是另一个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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