Question

I have an Android app that will be distributed in two (or more) brands. All java code for each distributions is exactly same, just different assets/resources (like layouts, drawables, dimensions, etc)

What is the best way to organize the project? I am using Git for version control, and trying to keep all distributions developed as a single project. So I can switch asset/resource sets easily for different branding each time needed.

Is there a good approach for it?

Was it helpful?

Solution 2

Gradle Build Variants allow you to have a shared main codebase/resources and multiple variants with custom resources/code associated with each - you then can generate a separate APK for each variant. Of course, using Gradle for Android development requires you use Android Studio (which is currently in beta) as well.

OTHER TIPS

One good approach would be turning your main project code in a library and then, for the other projects (brands), import that library and override the assets as you want.

As mentioned above, Gradle Build Variants is the best way to handle this. We have 11 variants (and counting) where the only difference are some configuration values. I organized the project as follows:

app/src/configurations/
   flavor1/
      common/res/...
      release/res/...
      stage/res/...

where the common directory holds configurations common to that build variant and the release and stage hold custom values for our release and staging versions (they have slightly different configurations as well).

All configurations common to all build variants live in the normal app/src/main/res folder.

Then in the app's build.grade, I have each product flavor defined:

productFlavors {
    flavor1 {
       applicationId = "com.example.flavor1"
    }

    flavor1stage {
        applicationId = "com.example.flavor1stage"
    }

    // etc. for each build flavor
}

android.sourceSets.flavor1 {
   res {
      srcDirs = ['src/configurations/flavor1/release/res', 'src/configurations/flavor1/common/res', 'src/res']
    }
}

android.sourceSets.flavor1stage {
    res {
       srcDirs = ['src/configurations/flavor1/stage/res', 'src/configurations/flavor1/common/res', 'src/res']
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top