Я разрабатываю приложение с Android Studio 1.0.2 и Gradle 1.0.0, используя библиотеки Apache httpmime
и httpcore
для многочастных объектов. Здесь мой 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'
}
Само приложение и "нормальные" APK файлы работают нормально, но когда я пытаюсь использовать ProGuard, я получаю следующее сообщение об ошибке:
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.
В соответствии с ссылками, приведенными в сообщении об ошибке, о повторяющихся определениях классов и классах библиотек в зависимости от классов программ, я должен использовать что-то вроде -injars ...
или -libraryjars ...
в моем proguard-rules.pro
. Но поскольку я использую удаленные библиотеки, а не файлы .jar
, я не знаю, как использовать эти параметры proguard.
Итак, я искал решение для своей проблемы и нашел несколько возможностей:
-
Я загрузил банки, добавил их в мою папку
\app\libs
и добавил параметры-libraryjar
и/или-injar
для обоих баннеров, но никакая комбинация не работала: либо файлы не могли быть найдены или прочитать, или я получил сообщение об ошибке, что одна из библиотек будет обрабатываться дважды. -
Я также пробовал различные комбинации
-keep class org.apache.**
,-keep interface org.apache.**
,-keep public class org.apache.** {*;}
,-keepnames class org.apache.** {*;}
с или без{*;}
, но никто из них не работает. -
Я также попробовал параметр
-dontwarn org.apache.**
или-dontwarn org.apache.http.**
, который не дает мне никаких ошибок при создании APK, но когда я пытаюсь установить подключение к Интернету с помощью http * libs в приложении, приложение вылетает с что-то вроде исключения NoSuchMethodException.
Итак, мой вопрос: есть ли способ использовать удаленные библиотеки и proguard? Или, по крайней мере, это возможно, включив .jars в папку \libs?
Большое спасибо