我有一个旧的 eclipse 项目,我已经搬到了 android studio 并设置为使用风味。在我开始尝试在我的风格之间使用不同的 java 文件之前,它似乎工作正常。
我的项目设置是这样的:
ProjectRoot
+- acitonbarsherlock
+- facebook
+- myLib1
+- myProject
+- src
+- commonFiles
+- flavor1
+- flavor2
+- res
+- flavor1
+- flavor2
myProject gradle 文件 android 闭包的内部结构如下所示:
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
signingConfigs {
...
}
productFlavors {
flavor2 {
}
flavor1 {
}
}
sourceSets{
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/commonFiles/java']
resources.srcDirs = ['src/commonFiles/java']
aidl.srcDirs = ['src/commonFiles/java']
renderscript.srcDirs = ['src/commonFiles/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
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']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
使用我这样的设置,gradle 抱怨无法找到我试图从flavor1 或flavor2 中的commonFiles 继承的类。
从我在这里看到的其他各种主题中,我看到其他人甚至没有定义源集,我觉得我在其中所做的可能太多了。
有没有人尝试过这个并且知道应该如何正确配置?