android-library with specific Product Flavors depe

2020-03-15 05:37发布

问题:

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'.

回答1:

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.