簡體   English   中英

什么是正確的Android Legacy Apache Http Proguard規則和配置?

[英]What are the correct Android Legacy Apache Http Proguard rules and configuration?

我有一個Android AsyncTask,它使用舊版Apache進行HTTP調用。 當我以非最小化的構建變體(即未混淆或縮小)運行此代碼時,HTTP調用成功完成。 一旦我使用minifyEnabled true ,代碼就會因以下錯誤而中斷:

java.lang.RuntimeException: An error occurred while executing doInBackground()
Caused by: java.lang.VerifyError: Verifier rejected class MyAsyncTask:

    java.lang.Object MyAsyncTask.doInBackground(java.lang.Object[]) failed to verify:
    java.lang.Object MyAsyncTask.doInBackground(java.lang.Object[]):
    [0x24] 'this' argument 'Precise Reference:
    org.apache.http.impl.client.DefaultHttpClient' not instance of 'Reference:
    org.apache.http.impl.client.CloseableHttpClient' (declaration of 'MyAsyncTask' appears in /data/app/org.xx-w1slvEAYxDsAOEktrVoz3A==/base.apk!classes2.dex)

有問題的代碼在doInBackground方法內部,如下所示:


DefaultHttpClient httpClient = new DefaultHttpClient();
HttpHead httpHead = new HttpHead("aUrl");

final HttpParams httpParameters = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_VALUE);
HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_VALUE);

HttpResponse response = httpClient.execute(httpHead);

我設置了以下proguard規則:

-dontwarn org.apache.commons.**
-dontwarn org.apache.http.**
-keep class android.net.http.** { *; }
-keep interface org.apache.** { *; }
-keep enum org.apache.** { *; }
-keep class org.apache.** { *; }
-keep class org.apache.commons.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.harmony.** {*;}

我在useLibrary 'org.apache.http.legacy'使用useLibrary 'org.apache.http.legacy'

我還添加了apache依賴項:

httpCore: org.apache.httpcomponents:httpcore:4.4.10,
httpMime: org.apache.httpcomponents:httpmime:4.5.6,
httpClient: org.apache.httpcomponents:httpclient:4.5.6

此設置可與Android Gralde插件3.1.2一起使用,但對於3.4.1則失敗。

我的proguard配置不正確嗎? 還是我必須更新代碼以使用CloseableHttpClient?

刪除這些Apache依賴項,並使用useLibrary "org.apache.http.legacy"代替。

將它們都添加是無稽之談,因為不確定哪個引用和打包。

如果MyAsyncTask的導入被破壞,則可能已經引用了Apache庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM