Je développe une application avec Android Studio 1.0.2 et Gradle 1.0.0 à l'aide des bibliothèques Apache httpmime
et httpcore
pour des entités en plusieurs parties. Voici mon 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'
}
L'application elle-même et la version "normale" des APK fonctionnent bien, mais lorsque j'essaie d'utiliser ProGuard, le message d'erreur suivant s'affiche:
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.
En fonction des liens indiqués dans le message d'erreur concernant les définitions de classe en double et les classes de bibliothèque en fonction des classes de programme, je devrais utiliser quelque chose comme -injars ...
ou -libraryjars ...
dans mon proguard-rules.pro
. Mais comme j'utilise les bibliothèques distantes et non les fichiers .jar
, je ne sais pas comment utiliser ces options de proguard.
J'ai donc cherché sur Google une solution à mon problème et j'ai trouvé plusieurs possibilités:
J'ai téléchargé les fichiers jar, les ai ajoutés à mon dossier \app\libs
et les options -libraryjar
et/ou -injar
pour les deux fichiers, mais aucune combinaison ne fonctionnerait. Soit les fichiers étaient introuvables ou ne pouvaient pas être lus, soit un message d'erreur les bibliothèques seraient traitées deux fois.
J'ai également essayé diverses combinaisons de -keep class org.Apache.**
, -keep interface org.Apache.**
, -keep public class org.Apache.** {*;}
, -keepnames class org.Apache.** {*;}
avec ou sans le {*;}
, mais aucune d'entre elles ne fonctionne.
J'ai également essayé l'option -dontwarn org.Apache.**
ou -dontwarn org.Apache.http.**
qui ne me donne aucune erreur lors de la création de l'APK, mais lorsque j'essaie d'établir une connexion Internet à l'aide de http * libs dans l'application, l'application se bloque avec quelque chose comme une exception NoSuchMethodException.
Ma question est donc la suivante: existe-t-il un moyen d’utiliser les bibliothèques distantes et proguard? Ou est-ce au moins possible en incluant les fichiers .jars dans mon dossier\libs?
Merci beaucoup
Eh bien, j'utilise comme ça
-dontwarn org.Apache.commons.**
-keep class org.Apache.http.** { *; }
-dontwarn org.Apache.http.**
Aussi je suis en train de compiler en utilisant jar dans mon dossier libs
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')
au lieu d'utiliser de maven
Essaye ça
-dontwarn org.Apache.commons.**
-keep class org.Apache.http.** { *; }
-dontwarn org.Apache.http.**
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }