I have an application with 2 product flavors and as a result 4 build variants:
1) freeDebug
2) freeRelease
3) paidDebug
4) paidRelease
I have a Fragment
that contains an ad, and it takes 2 lines to implement:
@Nullable @BindView (R.id.bottomsheet_ad) AdView mAdView;
mAdView.loadAd(adRequest);
So because of 2 lines, I have to potentially maintain 2 or more files.
I'm considering 2 solutions:
1) Check flavor at runtime:
if (BuildConfig.FLAVOR.equals("flavor123")) {
...
}
2) Create a common flavor and point needed variants in gradle, as explained here:
android {
...
productFlavors {
flavorOne {
...
}
flavorTwo {
...
}
flavorThree {
...
}
flavorFour {
...
}
}
sourceSets {
flavorOne.java.srcDir 'src/common/java'
flavorTwo.java.srcDir 'src/common/java'
flavorThree.java.srcDir 'src/common/java'
}
}
Which solution would be better? And is checking flavor at runtime as above considered polluting the code?