如何在Android build.gradle中忽略隐藏的目录 [英] How to ignore hidden directories in Android build.gradle

查看:902
本文介绍了如何在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
    }
}

这篇关于如何在Android build.gradle中忽略隐藏的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆