Domanda

I have an app which is going to have multiple instances. The instances will differ in some resources, which can be divided into two groups:

  1. differs only in (un)commented code, whole code is present
    • colors
    • strings
    • small differences in layouts (e.g. in one instance some components will be gone, in another instance they will be visible, but code remains)
  2. complete substitution (name, files)
    • package name
    • drawables
    • certificates in res/raw (all certs mustn't be stored there, only for particular instance)

What is the best approach to deal with these requirements? Use different git branches?

I use git (smartgit client). I guess that all requirements could be met when I use different branches for different instances. But I am afraid that this approach won't work for second group - complete substitution (name, files). Any suggestions?

PS: I understand that When adding new features I need to merge from some master branch into all other branches.

È stato utile?

Soluzione

After all git approach wasn't that right. Building multiple app instances (product flavours) with Gradle was just the right thing to do:

1) Specific files and resources per the instance of app

colors and strings are located in resource files: Project/module/src/instance_name/res/values/instance_name_cfg.xml.

layouts are located in: Project/module/src/instance_name/res/layout/instance_name_cfg.xml

Java code is located in: Project/module/src/instance_name/java/package.name/MyClass.java

drawables (PNG images) are located in: Project/module/src/instance_name/res/drawable/, ic_launcher images are in the same path only in different folders (drawable-hdpi,...)

Common files and resources are located in Project/module/src/main/ folder.

2) In the first picture there is the whole file structure.

Instances are in my case cities (Dammam, Jeddah, Prague, Reading). Screenshots are taken from Android Studio, where you can switch build variants (flavours) - at the bottom of the picture.

enter image description here

3) In the second picture there is a fragment of the build.gradle file.

Mixing app (instance) resources is quite powerful. As you can see in the picture below, resources, java files and even manifest files could be combined together in directive sourceSets. For example Dammam and Jeddah have the same java files, some common resources and specific resources per instance. Using name of instance (e.g. dammam) in sourceSets must precede declaration in directive productFlavours.

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top