如何在Android build.gradle中忽略隐藏的目录
我最近更新了一个现有的Android项目以使用Android Studio,并且无法构建它:
I've recently updated an existing Android project to use Android Studio, and haven't been able to get it to build:
Execution failed for task ':mergeDebugResources'.
> Index: 0
经过一番尝试,我发现它在我们的源代码控制的隐藏目录上窒息。 arch-id,它存在于每个文件夹中。
After some experimenting I've found that it's choking on our source control's hidden directories, .arch-ids, which exist in every folder.
我尝试使用exclude关键字操作build.gradle,无济于事:
I've tried manipulating build.gradle with the exclude keyword, to no avail:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java {
srcDirs = ['src']
exclude '**/.arch-ids/*'
}
resources {
srcDirs 'src'
exclude '**/.arch-ids/*'
}
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res {
srcDirs = ['res']
}
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
'res'部分似乎是momen的罪魁祸首t,但它不支持'exclude'关键字。
The 'res' part seems to be the culprit at the moment, but it doesn't support the 'exclude' keyword.
b
$ b
You may try something like:
android {
...
sourceSets {
main {
...
res.srcDirs = ['build/filtered_resources']
...
}
...
}
,然后使用过滤资源的任务依赖关系复制:
and then task dependency to use filtered resources copy:
task __filteredResources(type:Copy) {
from('res/') {
exclude '**/.arch-ids/*'
}
into 'build/filtered_resources'
includeEmptyDirs = true
}
tasks.whenTaskAdded { task ->
if (task.name == 'generateBuildConfig') {
task.dependsOn __filteredResources
}
}