Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - inherit product flavor

Tags:

android

gradle

I have 3 product flavors excluding the main one:

productFlavors {
    xxx {
        applicationId 'com.xxx'
    }
    yyy {
        applicationId 'com.yyy'
    }
    zzz {
        applicationId 'com.zzz'
    }
}

As I understand it, these product flavors inherit main's resources and it looks something like this:

        +------->xxx
        |           
main----+------->yyy
        |           
        +------->zzz

So when I build xxx, Gradle bundles stuff from src/main and from src/xxx folders.

Now, I need it to look like this:

        +------->xxx           
        |                      
main----+------->yyy------->zzz

In other words, I want zzz to use yyy's resources as well as main's. Can Gradle do this?

like image 358
Egor Neliuba Avatar asked Jul 23 '15 08:07

Egor Neliuba


2 Answers

It may depends on what exactly you want to "override" in zzz. In my project I need productFlavor inheritance too. But I needed override manifest only. I created directory for zzz with custom AndroidManifest.xml and changed other zzz src paths to yyy in build.gradle:

sourceSets {
    zzz.java.srcDirs = ['src/yyy/java']
    zzz.res.srcDirs = ['src/yyy/res']
    ...
    ...
}

productFlavors {
   xxx {}
   yyy {}
   zzz {}
}

P.S. Created a feature request for this https://code.google.com/p/android/issues/detail?id=183350

like image 122
Kirill Olenyov Avatar answered Oct 10 '22 11:10

Kirill Olenyov


I have answered this in another thread. I will just copy and paste my answer here, hoping it will be helpful to you.

I was looking for a similar thing in gradle and found Multi-flavor variants. I have an app that should have versions A and B, and each version has dev and pro environments, so I ended up with this in my gradle:

flavorDimensions 'app', 'environment'

productFlavors {
    versionA {
        flavorDimension 'app'
    }
    versionB {
        flavorDimension 'app'
    }
    pre {
        flavorDimension 'environment'
    }
    pro {
        flavorDimension 'environment'
    }
}

And in my build variants I have versionAPreDebug, versionAPreRelease, versionBPreDebug, versionBPreRelease, etc. I think what you need is something like that.

like image 45
allo86 Avatar answered Oct 10 '22 09:10

allo86