Victor CS
Victor CS

Reputation: 71

Product flavors, how to use custom class

I found this link but I have doubts. I have some doubts about Product flavors in android studio. I have a structure something like this:

app > src > main > java > com > mycompany > product > packages(view/ utils/ etc)

      > app2 > java > com > mycompany > product > packages(view/ utils/ etc)

      > app3 > java > com > mycompany > product > packages(view/ utils/ etc)
  1. How can I use a class in the main pack but with changes of code snippets for a specific build? I know there is the possibility of using a buildConfigField with a flag for use if and use code snippets in a class, but I think it bad and was wondering if you can use the same class or other means to use these snippets of code. I tried to create the same package structure and create a personalized copy of the class, but Android Studio complains of double class, something that does not occur with the res files.

  2. How can I generate apks in debug and simultaneous release for each build.

  3. How do simultaneous tests for each build.

Upvotes: 1

Views: 1484

Answers (1)

Alexander
Alexander

Reputation: 48272

Say, you have main and 2 flavors 'free' and 'paid'

1) You either have a file MyFile.java in src/main and then it goes to both flavors

Or you have src/free/MyFile.java and src/paid/MyFile.java then the files will be different per flavors

Or you have src/free/MyFile.java and no such file in src/paid then MyFile.java will only be used by 'free' flavor

(Edited: this last case will only compile if MyFile.java is not referred by anything in the src/main)

2) Use gradlew assembleDebug to generate all flavors for a debug build or gradlew assembleFreeDebug or gradlew assemblePaidDebug to generate only free or paid flavor. Same for release.

3) Same as 2) I don't remember target names

Android Studio has 'Build Variants' window in which you can take care of 2) and 3)

Upvotes: 1

Related Questions