Android – Proguard con httpcore y httpmime con Android Studio y Gradle

Estoy desarrollando una aplicación con Android Studio 1.0.2 y Gradle 1.0.0 usando las bibliotecas Apache httpmime y httpcore para entidades multipart. Aquí está mi build.gradle :

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

La aplicación en sí y la versión "normal" APKs funcionan bien, pero cuando estoy tratando de usar ProGuard recibo el siguiente mensaje de error:

 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'. > java.io.IOException: Please correct the above warnings first. 

De acuerdo con los enlaces que aparecen en el mensaje de error sobre las definiciones de clases duplicadas y las clases de biblioteca en función de las clases del programa, debería usar algo como -injars ... o -libraryjars ... en mi proguard-rules.pro . Pero ya que uso las bibliotecas remotas y no los archivos .jar no sé cómo usar estas opciones proguard.

Así que busqué una solución para mi problema y encontré varias posibilidades:

  • -libraryjar los frascos, los agregué a mi carpeta \app\libs y añadí las opciones -libraryjar y / o -injar para ambos frascos, pero no funcionaría ninguna combinación: Los archivos no se podían encontrar o leer, Error que uno de los libs se procesará dos veces.

  • También he intentado varias combinaciones de -keep class org.apache.** , -keep interface org.apache.** , -keep public class org.apache.** {*;} , -keepnames class org.apache.** {*;} Con o sin el {*;} pero ninguno de ellos funciona.

  • También intenté la -dontwarn org.apache.** o -dontwarn org.apache.http.** que no me da errores durante la creación del APK, pero cuando intento establecer una conexión a Internet usando las http * libs en el App, la aplicación se bloquea con algo como una excepción NoSuchMethodException.

Así que mi pregunta es: ¿hay alguna manera de usar las bibliotecas remotas y proguard? ¿O es al menos posible incluyendo los .jars en mi carpeta \ libs?

Muchas gracias

One Solution collect form web for “Android – Proguard con httpcore y httpmime con Android Studio y Gradle”

Bueno, yo estoy usando esto

 -dontwarn org.apache.commons.** -keep class org.apache.http.** { *; } -dontwarn org.apache.http.** 

También estoy compilando usando el tarro dentro de mi carpeta de las librerías

 compile files('libs/httpmime-4.3.5.jar') compile files('libs/httpclient-4.3.5.jar') compile files('libs/httpclient-cache-4.3.5.jar') compile files('libs/httpcore-4.3.2.jar') 

En lugar de usar desde maven

  • ProGuard y Gson en Android (ClassCastException)
  • Error de compilación referenciando archivo build.xml y proguard: "null returned: 1"
  • Siempre ejecutando proguard antes de Android dex'ing en Eclipse
  • Ejecución de ProGuard con una biblioteca AQuery
  • Error Proguard Número de versión de clase no admitido
  • No se puede generar APK firmado con proguard habilitado cuando se usa Joda Time
  • NoClassDefFoundError: android.support.design.internal.NavigationMenu en Android 4.2.2 (wiko)
  • Proguard y Android :(
  • Android Proguard no está en línea
  • Aplicación de Proguard a una aplicación existente en Google Play
  • Proguard infierno - no puede encontrar la clase referenciada
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.