4

是否可以更改默认风味根路径?

从:

---src
-----main
-----flavor1
-----flavor2
-----flavor3

至:

---src
-----main
-----flavors
--------flavor1
--------flavor2
--------flavor3
4

3 回答 3

7

如果您不想在每次添加风味时都在 sourceSets 中添加一行,则可以使用这样的闭包

productFlavors{
    flavor1 {}
    flavor2 {}

    all { flavor ->
        sourceSets[flavor.name].setRoot("src/flavors/${flavor.name}")
    }
}
于 2015-05-13T16:21:13.943 回答
2

您可以通过使用sourceSets.

productFlavors {
    flavor2 {
    }
    flavor1 {
    }
}

sourceSets{

    flavor2 {
        manifest.srcFile 'AndroidManifest-flavor2.xml'
        res.srcDirs = ['res-flavor2', 'res']
        java.srcDirs = ['src/flavor2/java','src/commonFiles/java']
        resources.srcDirs = ['src/flavor2/java','src/commonFiles/java']
        aidl.srcDirs = ['src/flavor2/java','src/commonFiles/java']
        renderscript.srcDirs = ['src/flavor2/java','src/commonFiles/java']
    }

    flavor1 {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src/flavor1/java','src/commonFiles/java']
        resources.srcDirs = ['src/flavor1/java','src/commonFiles/java']
        aidl.srcDirs = ['src/flavor1/java','src/commonFiles/java']
        renderscript.srcDirs = ['src/flavor1/java','src/commonFiles/java']
        res.srcDirs = ['res-flavor1','res']
        assets.srcDirs = ['assets']
    }

}
于 2015-04-28T14:27:05.790 回答
1

诚然,这可以实现,sourceSets但正确且更简单的解决方案是:

productFlavors{
    flavor1 {}
    flavor2 {}
}

sourceSets{
    flavor1.setRoot('src/flavors/flavor1')
    flavor2.setRoot('src/flavors/flavor2')
}
于 2015-04-29T07:18:30.327 回答