假设我有这样的build.gradle:

android {
    productFlavors {
        flavor1 {
        }
        flavor2 {
        }
    }
}

如何指定不同的依赖项,例如:
dependencies {
    flavor1DebugCompile ...
    flavor1ReleaseCompile ...
    flavor2DebugCompile ...
    flavor2ReleaseCompile ...
}

Gradle将生成错误,例如:Could not find method flavor1DebugCompile() for arguments ...

最佳答案

这是一个错误。
试试这个:

def customDeps = [
    flavor1DebugCompile   : dependencies.project(path: ':yourproject', configuration: 'flavor1Debug'),
    flavor2DebugCompile   : dependencies.project(path: ':yourproject', configuration: 'flavor2Debug'),
    flavor1ReleaseCompile : dependencies.project(path: ':yourproject', configuration: 'flavor1Release'),
    flavor2ReleaseCompile : dependencies.project(path: ':yourproject', configuration: 'flavor2Release'),
]

configurations.all() { config ->
    Dependency d = customDeps.get(config.name)
    if (d != null) {
        config.dependencies.add(d)
    }
}

关于android-studio - Gradle中不同口味和构建类型的不同依赖关系,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32292831/

10-10 14:39