0

I'm looking for the way how to load my properties per product flavor.

I do have right now:

productFlavors {
    flavor1 {
        println 'Flavor 1'
        loadProperties('flavor1.properties')
    }

    flavor2 {
        println 'Flavor 2'
        loadProperties('flavor2.properties')
    }

I'm using that properties to filter/process some resources before build.

If I do configure my build for one flavor, and run it through Android studio - I could find that two flavors executed and there are two println in console:

Flavor 1
Flavor 2

Is that possible somehow to find active product flavor per build? Something like get active (or current) product flavor and get access to all properties there? Or even find a way to process resources per different flavors?

Or may be define some property underFlovors and re use it in another place?

Redwid
  • 313
  • 1
  • 2
  • 9
  • 1
    See http://stackoverflow.com/questions/22506290/buildconfigfield-depending-on-flavor-buildtype/22512525#22512525 . The behavior you're seeing now happens because Gradle executes everything in that part of your build file during configuration phase; it doesn't selectively execute only the code for a given flavor. I suspect, though, that you're trying to do something unnecessarily complicated, and putting complex logic in your build file probably isn't the way to go. If you add more details to your question about what you want you may get a simpler answer. – Scott Barta Aug 12 '14 at 15:13
  • That overcomplicated to my task. – Redwid Aug 13 '14 at 13:17

1 Answers1

0

Found the way how to get current build flavor:

android.applicationVariants.all{ variant ->
    variant.processResources.doFirst {
        println '' + project.getName() + ', flavorName: ' + flavorName
        //Processing my resources there
    } 
}
Redwid
  • 313
  • 1
  • 2
  • 9