title: Android - Proguard with httpcore and httpmime using Android Studio and Gradle
body: <p>I'm developing an app with Android Studio 1.0.2 and Gradle 1.0.0 using the Apache libraries <code>httpmime</code> and <code>httpcore</code> for multipart entities. Here's my <code>build.gradle</code>:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.1"
  
      // Something wrong with the http* libs
      packagingOptions {
          exclude 'META-INF/DEPENDENCIES'
          exclude 'META-INF/NOTICE'
          exclude 'META-INF/LICENSE'
          exclude 'META-INF/DEPENDENCIES.txt'
          exclude 'META-INF/LICENSE.txt'
          exclude 'META-INF/NOTICE.txt'
          exclude 'META-INF/NOTICE'
          exclude 'META-INF/LICENSE'
          exclude 'META-INF/DEPENDENCIES'
          exclude 'META-INF/notice.txt'
          exclude 'META-INF/license.txt'
          exclude 'META-INF/dependencies.txt'
          exclude 'META-INF/LGPL2.1'
      }
  
      defaultConfig {
          // ...
      }
  
      buildTypes {
          release {
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile "com.android.support:support-v4:21.0.2"
      compile 'org.apache.httpcomponents:httpcore:4.3.2'
      compile 'org.apache.httpcomponents:httpmime:4.3.5'
      compile 'net.hockeyapp.android:HockeySDK:3.5.0'
  }
  </code></pre>
  
  <p>The app itself and the 'normal' release APKs work fine, but when I'm trying to use ProGuard I get the following error message:</p>
  
  <pre><code>Note: there were 157 duplicate class definitions.
        (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
  Warning:library class org.apache.http.auth.AuthenticationException extends or implements program class org.apache.http.ProtocolException
  Warning:library class org.apache.http.auth.MalformedChallengeException extends or implements program class org.apache.http.ProtocolException
  Warning:library class org.apache.http.auth.params.AuthParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean
  Warning:library class org.apache.http.client.NonRepeatableRequestException extends or implements program class org.apache.http.ProtocolException
  Warning:library class org.apache.http.client.RedirectException extends or implements program class org.apache.http.ProtocolException
  Warning:library class org.apache.http.client.entity.UrlEncodedFormEntity extends or implements program class org.apache.http.entity.StringEntity
  Warning:library class org.apache.http.client.methods.HttpEntityEnclosingRequestBase extends or implements program class org.apache.http.HttpEntityEnclosingRequest
  Warning:library class org.apache.http.client.methods.HttpRequestBase extends or implements program class org.apache.http.message.AbstractHttpMessage
  Warning:library class org.apache.http.client.methods.HttpUriRequest extends or implements program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.client.params.AllClientPNames extends or implements program class org.apache.http.params.CoreConnectionPNames
  Warning:library class org.apache.http.client.params.AllClientPNames extends or implements program class org.apache.http.params.CoreProtocolPNames
  Warning:library class org.apache.http.client.params.ClientParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean
  Warning:library class org.apache.http.client.protocol.RequestAddCookies extends or implements program class org.apache.http.HttpRequestInterceptor
  Warning:library class org.apache.http.client.protocol.RequestDefaultHeaders extends or implements program class org.apache.http.HttpRequestInterceptor
  Warning:library class org.apache.http.client.protocol.RequestProxyAuthentication extends or implements program class org.apache.http.HttpRequestInterceptor
  Warning:library class org.apache.http.client.protocol.RequestTargetAuthentication extends or implements program class org.apache.http.HttpRequestInterceptor
  Warning:library class org.apache.http.client.protocol.ResponseProcessCookies extends or implements program class org.apache.http.HttpResponseInterceptor
  Warning:library class org.apache.http.conn.BasicManagedEntity extends or implements program class org.apache.http.entity.HttpEntityWrapper
  Warning:library class org.apache.http.conn.ManagedClientConnection extends or implements program class org.apache.http.HttpClientConnection
  Warning:library class org.apache.http.conn.ManagedClientConnection extends or implements program class org.apache.http.HttpInetConnection
  Warning:library class org.apache.http.conn.OperatedClientConnection extends or implements program class org.apache.http.HttpClientConnection
  Warning:library class org.apache.http.conn.OperatedClientConnection extends or implements program class org.apache.http.HttpInetConnection
  Warning:library class org.apache.http.conn.params.ConnConnectionParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean
  Warning:library class org.apache.http.conn.params.ConnManagerParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean
  Warning:library class org.apache.http.conn.params.ConnRouteParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean
  Warning:library class org.apache.http.cookie.MalformedCookieException extends or implements program class org.apache.http.ProtocolException
  Warning:library class org.apache.http.cookie.params.CookieSpecParamBean extends or implements program class org.apache.http.params.HttpAbstractParamBean
  Warning:library class org.apache.http.impl.client.ClientParamsStack extends or implements program class org.apache.http.params.AbstractHttpParams
  Warning:library class org.apache.http.impl.client.EntityEnclosingRequestWrapper extends or implements program class org.apache.http.HttpEntityEnclosingRequest
  Warning:library class org.apache.http.impl.client.RequestWrapper extends or implements program class org.apache.http.message.AbstractHttpMessage
  Warning:library class org.apache.http.impl.client.TunnelRefusedException extends or implements program class org.apache.http.HttpException
  Warning:library class org.apache.http.impl.conn.DefaultClientConnection extends or implements program class org.apache.http.impl.SocketHttpClientConnection
  Warning:library class org.apache.http.impl.conn.DefaultResponseParser extends or implements program class org.apache.http.impl.io.AbstractMessageParser
  Warning:library class org.apache.http.impl.conn.LoggingSessionInputBuffer extends or implements program class org.apache.http.io.SessionInputBuffer
  Warning:library class org.apache.http.impl.conn.LoggingSessionOutputBuffer extends or implements program class org.apache.http.io.SessionOutputBuffer
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.client.HttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.client.methods.HttpEntityEnclosingRequestBase depends on program class org.apache.http.HttpEntity
  Warning:library class org.apache.http.client.methods.HttpRequestBase depends on program class org.apache.http.ProtocolVersion
  Warning:library class org.apache.http.client.methods.HttpRequestBase depends on program class org.apache.http.RequestLine
  Warning:library class org.apache.http.conn.scheme.PlainSocketFactory depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.conn.scheme.SchemeRegistry depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.conn.scheme.SocketFactory depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.conn.ssl.SSLSocketFactory depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpRequestExecutor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.ConnectionReuseStrategy
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.BasicHttpProcessor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpRequestExecutor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.ConnectionReuseStrategy
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.BasicHttpProcessor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpResponseInterceptor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpRequestInterceptor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpResponse
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpRequestExecutor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.ConnectionReuseStrategy
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpProcessor
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpHost
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.HttpRequest
  Warning:library class org.apache.http.impl.client.AbstractHttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.impl.client.DefaultHttpClient depends on program class org.apache.http.params.HttpParams
  Warning:library class org.apache.http.impl.client.DefaultHttpClient depends on program class org.apache.http.protocol.HttpRequestExecutor
  Warning:library class org.apache.http.impl.client.DefaultHttpClient depends on program class org.apache.http.protocol.HttpContext
  Warning:library class org.apache.http.impl.client.DefaultHttpClient depends on program class org.apache.http.ConnectionReuseStrategy
  Warning:library class org.apache.http.impl.client.DefaultHttpClient depends on program class org.apache.http.protocol.BasicHttpProcessor
  Warning:library class org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager depends on program class org.apache.http.params.HttpParams
  Warning:there were 109 instances of library classes depending on program classes.
           You must avoid such dependencies, since the program classes will
           be processed, while the library classes will remain unchanged.
           (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
  :app:proguardRelease FAILED
  Error:Execution failed for task ':app:proguardRelease'.
  &gt; java.io.IOException: Please correct the above warnings first. 
  </code></pre>
  
  <p>According to the links given in the error message about the duplicate class definitions and library classes depending on program classes I should use something like <code>-injars ...</code> or <code>-libraryjars ...</code> in my <code>proguard-rules.pro</code>. But since I use the remote libraries and not the <code>.jar</code> files I don't know how to use these proguard options.</p>
  
  <p>So I googled for a solution for my problem and found several possibilities:</p>
  
  <ul>
  <li><p>I downloaded the jars, added them to my <code>\app\libs</code> folder and added the options <code>-libraryjar</code> and/or <code>-injar</code> for both jars, but no combination would work: Either the files couldn't be found or read, or I got an error that one of the libs would be processed twice.</p></li>
  <li><p>I also tried various combinations of <code>-keep class org.apache.**</code>, <code>-keep interface org.apache.**</code>, <code>-keep public class org.apache.** {*;}</code>, <code>-keepnames class org.apache.** {*;}</code> with or without the <code>{*;}</code> but none of them work.</p></li>
  <li><p>I also tried the <code>-dontwarn org.apache.**</code> or <code>-dontwarn org.apache.http.**</code> option which gives me no errors during creating the APK, but when I try to establish an internet connection using the http* libs in the app, the app crashes with something like a NoSuchMethodException.</p></li>
  </ul>
  
  <p>So my question is: is there a way using the remote libraries and proguard? Or is it at least possible by including the .jars in my \libs folder?</p>
  
  <p>Thank you very much</p>