When using flavor products, which files are common in every taste and which files are specific to that taste?

productFlavors { India { } USA { } } 

Let's take 2 products as an example.

1. India 2. USA

the total number of assembly options will be 4

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

Which files are common to all tastes and which files have a specific taste, as well as debugging and release?

If localization is supported, and if English is a common language for India and the USA, will each assembly have a separate English file or a common file?

+1
source share
1 answer

Flavor is an amazing solution for creating different variations of the same application with separate functions.

Specific files

Let's say that one of your actions will have different functionality and user interface, then you can avoid saving this activity in a common package and move on to the appropriate taste. Each flavor can have a separate java and res folder along with a manifest (which is optional, Studio takes care of itself). This is where your specific Activity java file and xml file should be placed.

Example: the login screen will have different interfaces and functions in each flavor

Now at runtime, as well as compilation time, Android Studio switches between packages and selects the appropriate files. This is done using the Build Variant function.

enter image description here

Shared files

Thus, access to shared files that are applicable is all tastes, let it be in main/java and main/res itself.

Ideally, depending on your fragrance numbers, bundle.gradle would look something like 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' } } 

Now, to complete the answer, the files common to all the application will remain in the main package. Specific files applicable to the individual taste will be included in this flavor. This means flavors may have additional activity / features that are not part of others, including basic ones as well.

Follow this link for more information.

+1
source

Source: https://habr.com/ru/post/1262777/


All Articles