title: How to remove comments in raw XML files with Gradle when the file is packaged
body: <p>My project have XML files in the <strong>raw</strong> resource directory of my Android project:</p>
  
  <p><a href="https://i.stack.imgur.com/gYMRi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gYMRi.png" alt="Project Layout"></a></p>
  
  <p>I would like to remove comments (<code>&lt;!-- ... --&gt;</code>) from these files when it is packaged in <code>.apk</code> file:</p>
  
  <p><em>Original file sample:</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;celebrations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation="celebrations_schema.xsd"&gt;
  
      &lt;!-- This is a very important comment useful during development --&gt;
      &lt;celebration name="celebration 1" type="oneTime" ... /&gt;
  
      &lt;!-- This is another very important comment useful during development --&gt;
      &lt;celebration name="celebration 2" type="reccurent" ... /&gt;
  &lt;/celebrations&gt;
  </code></pre>
  
  <p><em>Expected filtered file:</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;celebrations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation="celebrations_schema.xsd"&gt;
      &lt;celebration name="celebration 1" type="oneTime" ... /&gt;
      &lt;celebration name="celebration 2" type="reccurent" ... /&gt;
  &lt;/celebrations&gt;
  </code></pre>
  
  <hr>
  
  <p>I have found some interesting similar solutions <a href="https://stackoverflow.com/a/25328289/868314">here</a>, but I can't manage it to work. Adding these lines in my app <code>build.gradle</code></p>
  
  <pre><code>processResources {
      filesMatching('**/myxmlfiletobestrippedfromcomments.xml') {
          filter {
              String line -&gt; line.replaceAll('&lt;!--.*--&gt;', '')
          }
      }
  }
  </code></pre>
  
  <p>generates the following error:</p>
  
  <pre><code>Error:(86, 0) Gradle DSL method not found: 'processResources()'
  </code></pre>
  
  <hr>
  
  <p>For opening and parsing the XML file from java code, I use the following method:</p>
  
  <pre><code>InputStream definition = context.getResources().openRawResource(resId);
  ...
  try {
      XmlPullParser parser = Xml.newPullParser();
      parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
      parser.setInput(definition, null);
      parser.nextTag();
      return parseCelebrations(parser);
  } finally {
      definition.close();
  }    
  </code></pre>