如何使用 Gradle 和 Android Studio 从资源中排除文件? [英] How to exclude file from resources using Gradle and Android Studio?
问题描述
我的项目中有一个生成的字符串资源 xml 文件,该文件是从扩展名为 .template 的文件生成的.我试图从构建中排除这个模板,因为它给了我重复的资源错误.以下对我不起作用,我被卡住了:
I have a generated string resource xml file in my project which is generated from a file with a .template extension. I'm trying to exclude this template from the build since it gives me duplicate resource error. The following does not work for me and I'm stuck:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['res']
resources.exclude '**/build_id.template'
res.srcDirs = ['res']
res.exclude '**/build_id.template'
assets.srcDirs = ['assets']
}
}
错误:
Error:Error: Duplicate resources: <project-dir>/res/values/build_id.template:string/build_id, <project-dir>/res/values/build_id.xml:string/build_id
如何正确排除特定资源文件?
How can I exclude a particular resource file properly?
推荐答案
为了其他在您项目上工作的人的理智,我强烈建议您不要将模板(输入)和自动生成的文件(输出)放在同一目录中.您可以创建自己的独立模板"目录,以防止其包含在您的构建中.
For the sanity of other folks working on your project, I strongly discourage putting templates (input) and auto-generated files (output) in the same directory. You could create your own, independent 'templates' directory to keep it from being included in your build.
这篇关于如何使用 Gradle 和 Android Studio 从资源中排除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!