V
V
Valery2016-06-30 13:33:53
Android
Valery, 2016-06-30 13:33:53

How to effectively maintain 2 projects with little difference in code?

At first we had only 1 project, but over time, it became necessary to make the same application with client branding (in other words, White-label product). The only differences from the original design were the colors, resources, and code for some of the classes.
I made the decision to make a copy of the branch in Git and push the changes. As a result, I now have 2 applications where code duplication is around 95%. The main problem is that making changes in the same code for applications is very time consuming, since these two branches cannot be merged. They have a different package, and the package name in Android corresponds to the path to the files on the disk. Accordingly, all files are simply located in different directories.
I took a look at Product Flavors. This solves the question "how to maintain 2 projects in one git branch", but it is not entirely clear how to effectively make changes. If I have 2 classes that are slightly different, I have to store them in different directories so that Gradle can pick up the right file when building.
But how to effectively make changes to the shared code for these files? You may have encountered this problem before.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexander Movchan, 2016-06-30
@Alexander1705

Do a fork .

H
Henry, 2016-06-30
@Henryh

I have 3 projects on the same code. I moved all the system (same) code to a subrepository. Thus, different colors do not have to be merged, since they are in different projects.
And if I fixed the system code in one of the projects, then it will improve in three projects at once, with the next update.

A
afishr, 2016-06-30
@afishr

And if all the same code is added to a separate branch. Then Create another branch for the first product, and another one for the second.
When changes are made to the shared code, you commit them to the master branch, then merge them into the branch of each product. And when the changes already concern only the functionality of one product, work only with its branch.

A
Andrey Andreev, 2016-06-30
@b0nn1e

We use git cherry-pick to move commits with "new features" to the desired branches.

A
Artem Gapchenko, 2016-06-30
@artemgapchenko

I could write a long answer, but luckily Hannes Dorfman already laid out my pain about maintaining two projects with a relatively common codebase a couple of months ago in his article , so I'm sending you to him.

V
vahaketiladze, 2016-06-30
@vahaketiladze

In one studio project, create a module that contains the common code.
And for each application, one more module, in which to prescribe the differences.
Link these modules and that's it.
I use this approach to support 14 applications in which only themes, names, icons and databases differ.
Different classes in projects can be implemented through an interface.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question