0

I have developed an app which I was developing under staging environment and now deployed it to production environment which would be uploaded in google play store. So, for both environment app I am using productFlavors which would build the different variant defining in the build gradle file.

My problem is: I am having some java files which I have to include in production build but not into staging build. How can I achieve this?

One of the solution: when I am selecting build variants I would add/delete the java files which is not the appropriate solution as I would update the app in future with more java files added to production

Edited: I don't want to make different src folder for different flavors. Wouldn't it be possible without making different folders? As I have already mentioned I'm having same code for different flavors.

Pankaj
  • 7,908
  • 6
  • 42
  • 65
  • 2
    Possible duplicate of [Using Build Flavors - Structuring source folders and build.gradle correctly](http://stackoverflow.com/questions/16737006/using-build-flavors-structuring-source-folders-and-build-gradle-correctly) – GreyBeardedGeek Jan 16 '16 at 18:57

1 Answers1

0

You create a folder in your src directory next to main where you will add files for one flavor. For example:

- src/
-- main/
-- production/

You put your extra Java files that should only be in the production flavor in that new folder.

sorianiv
  • 4,845
  • 1
  • 23
  • 27
  • Without it can't be possible to add files? Is there any other way? – Pankaj Jan 17 '16 at 05:22
  • From your comment and your edit, I see that I didn't quite understand your question. I don't understand why you don't want to add folders. Do you mean that you have more than 2 flavors and you want, for example, to share the same code in flavor 1 and 2, but not in flavor 3? – sorianiv Jan 17 '16 at 10:14
  • I want to have two flavors only both sharing same code but need to add some files in production one. what should be the best way to do it. – Pankaj Jan 17 '16 at 12:28
  • This is why you put in `main` all the code that will be shared. You refactor your code so that only the parts that reference your added files (the code that differs between staging and production) is in the `staging` and `production` folders. Then you add the extra files in `production`, which are only referenced by your production code. All the shared code stays in `main`. – sorianiv Jan 17 '16 at 12:36