Home » Android » java – android-library with specific Product Flavors dependency

java – android-library with specific Product Flavors dependency

Posted by: admin June 16, 2020 Leave a comment

Questions:

I’m looking for something like

apply plugin: 'android-library'

dependencies {
    flavor1Compile files('utility.aar')
}

Everything fails with:

Could not find method flavor1Compile() for arguments [file collection] on root project ‘SampleProject’.

How to&Answers:

Libraries don’t support flavors.

Note that this wouldn’t work in a app project because you haven’t defined the flavor first. You’d need to do

android {
    productFlavors {
        flavor1 {}
    }
}

dependencies {
    flavor1Compile ...
}

it wouldn’t work in the other order as declaring the product flavor is what create its associated dependency configuration.