【问题标题】:Apache HTTP client with sdk 23 and proguard带有 sdk 23 和 proguard 的 Apache HTTP 客户端
【发布时间】:2015-10-11 20:42:44
【问题描述】:

现在很多库都需要 compileSdkVersion 23。但是这个版本不包含 apache 并且一些旧的库使用了 apache http。对于使用 23 的 apache,我找到了解决方案,其中提到将 org.apache.http.legacy 添加到 grudle。
useLibrary 'org.apache.http.legacy'

这项工作。但不是用proguard。 我使用 proguard 来缩小 apk 大小,我不使用混淆,只使用 minifyEnabled true 在 'proguard-rules.txt' 我只有一个字符串:
-dontobfuscate
当我构建 apk AndroidStudio 时显示错误,因为某些库使用了 apache。我试图将保持类添加到 proguard 但这不起作用。每次我收到有关 apache 的错误时。

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

-keep class android.net.http.** { *; }
-dontwarn android.net.http.**

-keep class android.support.v7.** { *; }
-keep class android.support.v4.** { *; }

注意:当 proguard 被禁用时(minifyEnabled 设置为 false)然后 apk 构建和工作成功。 这是来自 android studio 控制台的错误示例:

:app:proguardRelease
Warning: com.vk.sdk.api.httpClient.VKHttpOperation: can't find referenced method 'org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest)' in program class com.vk.sdk.api.httpClient.VKHttpClient
Warning: org.acra.ErrorReporter: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification

还有更多

Warning: com.mopub.mobileads.VastVideoViewController: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning: com.mopub.mobileads.VastVideoViewController: can't find referenced class org.apache.http.client.methods.HttpGet
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.params.BasicHttpParams
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.mopub.mobileads.factories.HttpClientFactory: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning: com.mopub.mobileads.util.HttpClients: can't find referenced class org.apache.http.client.HttpClient
Warning: com.mopub.mobileads.util.HttpClients: can't find referenced class org.apache.http.client.HttpClient
Warning: com.mopub.mobileads.util.HttpClients$1: can't find referenced class org.apache.http.client.HttpClient
Warning: com.mopub.mobileads.util.HttpClients$1: can't find referenced class org.apache.http.client.HttpClient
Warning: com.mopub.mobileads.util.HttpClients$1: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning: com.mopub.mobileads.util.HttpClients$1: can't find referenced class org.apache.http.conn.ClientConnectionManager
Warning: com.mopub.mobileads.util.HttpClients$1: can't find referenced class org.apache.http.client.HttpClient
Warning: com.mopub.mobileads.util.HttpClients$1: can't find referenced class org.apache.http.client.HttpClient
Warning: com.mopub.mobileads.util.vast.VastXmlManagerAggregator: can't find referenced class android.net.http.AndroidHttpClient

【问题讨论】:

  • 不完全相同的错误,但可能是相同的原因:compileSdkVersion 23useLibrary 'org.apache.http.legacy' 不能与 minifyEnabled ture 一起正常工作。仍在努力寻找解决方案。

标签: java android apache android-studio proguard


【解决方案1】:

我刚刚遇到同样的问题,并通过以下方式解决了它:

  • 将 Android SDK 构建工具更新到 23.0。1

  • 将 MoPub 更新到 3.13.0

【讨论】:

  • 我已经有最新的 sdk 24.4 但这无济于事。也许我可以更新 mopub,但我有更多需要 apache 的库,我无法全部更新。
【解决方案2】:

google-play-services_lib 遇到了类似的问题。 通过将此行添加到 proguard-project.txt 在 Eclipse 中解决:

-libraryjars "<path to sdk>\platforms\android-23\optional\org.apache.http.legacy.jar"

setLatestEventInfo 方法也有同样的问题,它已在第 23 级被弃用并删除。这次没有遗留 jar。 再说一遍:

-libraryjars "<path to sdk>\platforms\android-22\android.jar"

有了这个引用,apache 的第一个可能是多余的 - 我现在只需要第一个,因为将 google-play-services_lib 升级到 8.2.98 版本(虽然最近,仍然引用 apache)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多