4

I have an Android app which is a paid app and I would like to make a free version. The source code will be 95% the same for the free version. I am using git for source control and my initial thought is to create a free branch off the master so I can easily merge changes from the paid version into the free one.

Is this the right strategy bearing in mind that some of the changes in the free branch will never be merged back into master?

Other options are:

  1. Creating another repo for the free version
  2. Keeping everything in master and creating library code which is used by both the free and paid versions
donturner
  • 17,867
  • 8
  • 59
  • 81

3 Answers3

2

I would prefer keeping the code together and using conditional compilation and/or "paid" plugin libraries over branches. A branch is supposed to represent diversion of the source tree during development. Branches should not be used to maintain separate codebases.

cdhowie
  • 158,093
  • 24
  • 286
  • 300
  • what do you mean with 'conditional compilation' ? – Francisco Corrales Morales Jan 20 '15 at 23:30
  • @FranciscoCorralesMorales For example, `#ifdef FULL_VERSION` etc. to produce a free and a full version out of the same codebase. (There is [a similar technique for Java](http://stackoverflow.com/questions/1813853/ifdef-ifndef-in-java).) – cdhowie Jan 21 '15 at 04:24
0

You can create a paid-master and a free-master. Using the git flow technique to manage your new features and bug fixes.

Tarsis Azevedo
  • 1,463
  • 14
  • 21
  • 2
    "git flow" is designed to manage how features develop, the management of versioned releases, and hotfixes. It is not designed to accommodate two different (but related) codebases in separate branches. – cdhowie Aug 21 '12 at 21:39
0

With the gradle build system, you are able to create different "flavors" for your app.

android { ... defaultConfig { ... } signingConfigs { ... } buildTypes { ... } productFlavors { paid { applicationId "donturner.app.paid" versionName "1.0-paid" } free { applicationId "donturner.app.free" versionName "1.0-free" } } }

You can then create additional source folders for these build flavors which can be used to provide different implementations. Eg. app/src/free/java/ClassWithDifferences.java would provide the "free" implementation app/src/paid/java/ClassWithDifferences.java.

Note: code in app/src/main/ is shared between all flavors; so there must not be app/src/main/java/ClassWithDifferences.java. And be sure to use these flavors correctly, e.g. a class that only exists in the free flavor must not be referenced in main, nor in paid.

lippertsjan
  • 309
  • 1
  • 18