0

So I am trying to architect my project based on a MVP pattern for Android. I have used this excellent article as my base. While it works great, I was wondering how would I be able to maintain different build flavors(Staging & Production) across modules.

More details -

I have a module named common which contains a Constants.java file which has URL's and other base settings/constants. What I want to be able to do is have different Constants.java file for staging and production. In the same module, it is easily done, but since my common module is separate from my main app module, I am not sure how would I achieve this.

Any pointers would be appreciated. Thanks

Adnan Mulla
  • 2,872
  • 3
  • 25
  • 35
  • 1
    You can use 2 different modules, one for debug one for release. If it is a single file, you can use 2 different java classes for debug/release. – Gabriele Mariotti Jun 22 '15 at 07:01
  • refer this http://stackoverflow.com/questions/5590203/create-free-paid-versions-of-application-from-same-code – Aniruddha K.M Jun 22 '15 at 07:29
  • @GabrieleMariotti That's one of way of doing but I guess thats as good as maintaining 2 different projects, if nothing else works I will end up doing that. Thanks for the help – Adnan Mulla Jun 22 '15 at 07:56

1 Answers1

0

Though I haven't done this myself yet, according to the documentation, you can have different flavors for your library module and reference them from a flavored app module as follows:

//:app build.gradle
productFlavors {
    stage {
    }

    prod {
    }
}

dependencies {
    stageCompile project(path: ':common', configuration: 'stageRelease')
    prodCompile project(path: ':common', configuration: 'prodRelease')
}

//:common build.gradle
android {
    publishNonDefault true
}

productFlavors {
    stage {
    }

    prod {
    }
}
Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59