How to exclude file from resources using Gradle and Android Studio?

旧街凉风 提交于 2019-12-09 18:22:08

问题


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']
       }
   }

The error:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/24721880/how-to-exclude-file-from-resources-using-gradle-and-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!