Reputation: 2202
Suppose I have lots of flavors:
android
{
productFlavors {
flavor1 { ... }
flavor2 { ... }
flavor3 { ... }
flavor4 { ... }
flavor5 { ... }
...
}
}
Instead of set the dependencies of the flavors one by one:
dependencies {
flavor1Compile fileTree(include: ['*.jar'], dir: 'src/flavor1/libs')
flavor2Compile fileTree(include: ['*.jar'], dir: 'src/flavor2/libs')
flavor3Compile fileTree(include: ['*.jar'], dir: 'src/flavor3/libs')
flavor4Compile fileTree(include: ['*.jar'], dir: 'src/flavor4/libs')
flavor5Compile fileTree(include: ['*.jar'], dir: 'src/flavor5/libs')
...
}
I want a simple way to loop over such as the pseudocode:
dependencies {
all {
entry ->
compile fileTree(include: ['*.jar'], dir: 'src/' + entry.name + '/libs')
}
}
Is this achievable with build.gradle? If so how to make it?
Upvotes: 0
Views: 159
Reputation: 2202
I found it out. Just loop the productFlavors
in the dependencies
and then call add
method manually:
dependencies {
android.productFlavors.each {
flavor ->
add(flavor.name + 'Compile', fileTree(include: ['*.jar'], dir: 'src/' + flavor.name + '/libs'))
}
}
Upvotes: 3