0

Duplicate class error with product flavors.

I have deleted my mainActivity from Main and inserted a copy into both of my product flavor folders "free" and "paid". But now inside the "free" flavor it says there is a duplicate inside "paid", and the same thing the other way around.. But am I not supposed to delete from main and insert a copy into all flavors I have?

  • WHy do you have separate folders for different flavors? The idea of flavors is you use one codebase, not multiple. Generally you'd have 1 activity that checks what flavor it is and changes its behavior accordingly. This way you don't duplicate the code and maintenance of common bugs. – Gabe Sechan Mar 01 '18 at 14:33
  • It's because i need one java class with ads for my free flavor and one java class without ads for my paid version. – Lars Nyborg Pedersen Mar 01 '18 at 14:37
  • So you put the ads in both, and hide them in the paid version by setting its visibility to GONE. Or you add them at runtime in the free version. YOu do not use two activities, that's just asking for pain. – Gabe Sechan Mar 01 '18 at 14:39
  • But how do I then make it act differently depending on which flavor it is? – Lars Nyborg Pedersen Mar 01 '18 at 14:43
  • Check BuildConfig.FLAVOR. See https://stackoverflow.com/questions/24119557/android-using-gradle-build-flavors-in-the-code-like-an-if-case – Gabe Sechan Mar 01 '18 at 14:45
  • now I have written this: – Lars Nyborg Pedersen Mar 01 '18 at 15:09
  • flavorDimensions "default" productFlavors { free { applicationId "com.larsnyborgpedersen.meditationforboern2.free" buildConfigField 'boolean', 'withAds', 'true' dimension "default" } paid { applicationId "com.larsnyborgpedersen.meditationforboern2.paid" buildConfigField 'boolean', 'withAds', 'false' dimension "default" } } – Lars Nyborg Pedersen Mar 01 '18 at 15:09
  • But I can't access buildConfigField from my java code..... Even though I write if (BuildConfig.withAds) – Lars Nyborg Pedersen Mar 01 '18 at 15:10
  • Your original approach sounds good. Could you post the directory structure? – serv-inc Jul 18 '18 at 15:45

0 Answers0