web-dev-qa-db-ja.com

Android-Android StudioおよびGradleを使用したhttpcoreおよびhttpmimeによるProguard

マルチパートエンティティのApacheライブラリhttpmimehttpcoreを使用して、Android Studio 1.0.2およびGradle 1.0.0でアプリを開発しています。ここに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ファイルではなくリモートライブラリを使用しているため、これらのプロガードオプションの使用方法がわかりません。

だから私は自分の問題の解決策を探していくつかの可能性を見つけました:

  • Jarをダウンロードして\app\libsフォルダーに追加し、両方のjarにオプション-libraryjar-injarを追加しましたが、組み合わせが機能しませんでした。ファイルが見つからなかったか、読み取れなかったか、エラーの1つがlibsは2回処理されます。

  • また、-keep class org.Apache.**-keep interface org.Apache.**-keep public class org.Apache.** {*;}-keepnames class org.Apache.** {*;}のさまざまな組み合わせを試してみましたが、{*;}の有無にかかわらず、どれも機能しませんでした。

  • APKの作成中にエラーが発生しない-dontwarn org.Apache.**または-dontwarn org.Apache.http.**オプションも試してみましたが、アプリでhttp *ライブラリを使用してインターネット接続を確立しようとすると、アプリがNoSuchMethodExceptionのようなものでクラッシュします。

だから私の質問は:リモートライブラリとプロガードを使用する方法はありますか?または、少なくとも.jarを\ libsフォルダーに含めることで可能ですか?

どうもありがとうございました

14
hilakista

まあ私はこのように使用しています

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

また、libsフォルダー内のjarを使用してコンパイルしています

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

mavenから使用する代わりに

33
goonerDroid

これを試して

-dontwarn org.Apache.commons.**
-keep class org.Apache.http.** { *; }
-dontwarn org.Apache.http.**
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
2
Ankit Aman