在使用产品风味时,每种风味中共有哪些文件,以及针对该风味有哪些文件? [英] While using product flavours what files are common in each flavour and what files are specific to that flavour?

查看:90
本文介绍了在使用产品风味时,每种风味中共有哪些文件,以及针对该风味有哪些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

productFlavors {
        India {

        }
        USA {

        }
    }

让我们以2种产品口味为例

Lets take 2 product flavours for an example

1.印度 2.美国

1. India 2. USA

构建变体的总数为4

1.印度调试 2.印度发行 3. USADebug 4. USARelease

1. IndiaDebug 2. IndiaRelease 3. USADebug 4. USARelease

哪些文件是所有版本共同的文件,哪些文件是特定版本的以及调试和发行版的?

Which files are common for all flavours and which files are flavour specific as well as debug and release specific ?

如果支持本地化并且如果英语是印度和美国的通用语言,那么每个版本将有单独的英语文件还是通用文件?

If localization is supported and if english is common language for India and USA then each build will have separate english file or common file ?

推荐答案

Product Flavor是一个很棒的解决方案,用于构建具有单个功能的同一应用程序的不同品种.

Product Flavour is a awesome solution to build different varieties of the same application with individual features.

特定文件

像一样,您的一个Activity将具有不同的功能和UI,那么您可以避免将该Activity放在同一包中,而转向各自的风格.每种口味可以与Manifest一起具有单独的javares文件夹(这不是强制性的,Studio会自行处理).应该在此处放置您特定Activity的Java文件和xml文件.

Say like , one of your Activity will have different functionality and UI, then you can avoid keeping that Activity in common package and move to respective flavour. Each flavour can have separate java and res folder along with Manifest (which is not mandatory, Studio take care of itself). It is here your specific Activity's java file and xml file should be placed.

示例:登录屏幕的每种口味都将具有不同的用户界面和功能

Example : Login Screen will have different UI and features in each flavour

现在在运行时和编译时,Android Studio会在程序包之间切换并选择合适的文件.这是通过Build Variant功能

Now during runtime as well as compile time, Android Studio switches between the packages and picks suitable files. This is done through Build Variant feature

公用文件

因此,所有常用的东西都可以进入通用文件,并放在main/javamain/res本身中.

So coming to common files which is applicable is all the flavours, let it be in main/java and main/res itself.

理想情况下,bundle.gradle取决于您的口味编号.

Ideally depending on your flavour numbers, bundle.gradle will look similar to this.

productFlavors {

        student {
            applicationId "com.abc.student"
        }
        staff {
            applicationId "com.abc.staff"
        }
        tempstaff {
            applicationId "com.abc.tempstaff"
        }
    }
sourceSets {
        tempstaff {
            manifest.srcFile 'src/tempstaff/AndroidManifest.xml'
        }
        student{
            manifest.srcFile 'src/student/AndroidManifest.xml'
        }
        staff {
            manifest.srcFile 'src/staff/AndroidManifest.xml'
        }
    }

现在要结束答案,在整个文档中很常见的文件 应用程序将保留在main包中.具体文件 适用于单独的风味将成为该风味.这表示 风味可以具有根本不存在的额外活动/功能 其他的,包括主要的

Now to conclude the answer, files which are common throughout the application will remain in the main package. Specific files applicable to separate flavour will go in that flavour. This means flavours can have extra Activity/Features that are not at all a part of others including main also

通过此链接以获取更多信息.

Go through this link for more information.

这篇关于在使用产品风味时,每种风味中共有哪些文件,以及针对该风味有哪些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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