title: Keep 'META-INF/services'-files in apk
body: <p>I have a custom charset which is already working on JavaSE.</p>
  
  <p>The class of my CharsetProvider is specified in a file <code>java.nio.charset.spi.CharsetProvider</code> which is located in <code>META-INF/services</code> and everything get's loaded normally and works as expected.</p>
  
  <p>However now I'm using the lib on android as well, but the charset isn't loaded in Android-App.</p>
  
  <p>How can I integrate my charset, so that it can be used like expected in an Android-App?</p>
  
  <pre><code>Charset.forName("MyCS");
  </code></pre>
  
  <p>At the moment I'm doing a workaround like this:</p>
  
  <pre><code>public static String decode(String encoding, byte[] buffer, int offset, int length) {
      String result = "";
      try {
          result = new String(buffer, offset, length, encoding);
      } catch (UnsupportedEncodingException ex) {
          MyCharsetProvider provider = new MyCharsetProvider();
          Charset cs = provider.charsetForName(encoding);
          if (cs == null) {
              Logger.getLogger(Converters.class.getName()).log(
                      Level.SEVERE,null,ex);
              result = new String(buffer, offset, length);
          } else {
              result = cs.decode(ByteBuffer.wrap(buffer, offset, length)).toString();
          }
      }
      return result;
  }
  </code></pre>
  
  <p>Which works, but seems ineffective to me, since everytime I try to decode like this with my own charset, an exception will be thrown and a CharsetProvider-Object will be created.</p>
  
  <p>The creation of course could be reduced by singleton pattern. But the issue is to avoid the direct usage of MyCharsetProvider entirely.</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>Since <code>META-INF/services/java.nio.charset.spi.CharsetProvider</code> is missing in the apk I though maybe proguard removes it. I then tried the following options in proguard.cfg:</p>
  
  <pre><code>-adaptresourcefilenames **.CharsetProvider
  -adaptresourcefilecontents **.CharsetProvider
  </code></pre>
  
  <p>But the problem still persists. so how can I get these files from <code>META-INF/services</code> into my apk automatically using ant (netbeans)?</p>