3

我们最近决定在我们的 Android 构建中禁用代码混淆,因为虽然它使最终的 APK 稍微大一些,但它使调试变得更加困难。

自从我们这样做以来,我一直在我们的应用程序中遇到以前不存在的崩溃,即当混淆仍然有效时。通常这些崩溃是由 JavaVerifyError或Java 引起NoSuchMethodError的。

以下是我在禁用混淆时突然看到的两个错误:

Could not find method org.apache.http.HttpConnectionMetrics.getResponseCount, referenced from method com.google.android.apps.analytics.PipelinedRequester.sendRequests
W/dalvikvm( 6652): VFY: unable to resolve virtual method 16112: Lorg/apache/http/HttpConnectionMetrics;.getResponseCount ()J
W/dalvikvm( 6652): VFY:  rejecting opcode 0x6e at 0x000c
W/dalvikvm( 6652): VFY:  rejected Lcom/google/android/apps/analytics/PipelinedRequester;.sendRequests ()V
W/dalvikvm( 6652): Verifier rejected class Lcom/google/android/apps/analytics/PipelinedRequester;
D/dalvikvm( 6652): GC_CONCURRENT freed 253K, 46% free 3261K/6023K, external 0K/0K, paused 2ms+2ms
I/dalvikvm( 6652): Rejecting re-init on previously-failed class Lcom/google/android/apps/analytics/PipelinedRequester; v=0x4062de30
D/AndroidRuntime( 6652): Shutting down VM
W/dalvikvm( 6652): threadid=1: thread exiting with uncaught exception (group=0x400a7560)
E/AndroidRuntime( 6652): FATAL EXCEPTION: main
E/AndroidRuntime( 6652): java.lang.VerifyError: com/google/android/apps/analytics/PipelinedRequester
... 

我可以通过 !class/merging/* 禁用类合并来解决此错误

我看到的另一个错误是:

I/dalvikvm( 7292): DexOpt: access denied from Lcom/urbanairship/analytics/EventUploadManager; to field Lorg/apache/http/entity/AbstractHttpEntity;.contentEncoding
W/dalvikvm( 7292): VFY: unable to resolve instance field 5188
D/dalvikvm( 7292): VFY: replacing opcode 0x5b at 0x00ec
I/dalvikvm( 7292): Could not find method org.apache.http.conn.scheme.PlainSocketFactory.<init>, referenced from method com.google.android.apps.analytics.PipelinedRequester.<init>
W/dalvikvm( 7292): VFY: unable to resolve direct method 15044: Lorg/apache/http/conn/scheme/PlainSocketFactory;.<init> (B)V
D/dalvikvm( 7292): VFY: replacing opcode 0x70 at 0x0003
D/dalvikvm( 7292): VFY: dead code 0x0006-0009 in Lcom/google/android/apps/analytics/PipelinedRequester;.<init> (Lorg/apache/http/HttpHost;)V
I/dalvikvm( 7292): DexOpt: access denied from Lcom/google/android/apps/analytics/PipelinedRequester; to field Lorg/apache/http/impl/SocketHttpClientConnection;.open
W/dalvikvm( 7292): VFY: unable to resolve instance field 5234
D/dalvikvm( 7292): VFY: replacing opcode 0x55 at 0x0006
D/dalvikvm( 7292): VFY: dead code 0x0008-000e in Lcom/google/android/apps/analytics/PipelinedRequester;.closeConnection ()V
D/dalvikvm( 7292): VFY: dead code 0x0010-0011 in Lcom/google/android/apps/analytics/PipelinedRequester;.closeConnection ()V
I/dalvikvm( 7292): DexOpt: access denied from Lcom/google/android/apps/analytics/PipelinedRequester; to field Lorg/apache/http/impl/SocketHttpClientConnection;.open
W/dalvikvm( 7292): VFY: unable to resolve instance field 5234
D/dalvikvm( 7292): VFY: replacing opcode 0x55 at 0x0006
D/dalvikvm( 7292): VFY: dead code 0x0008-0009 in Lcom/google/android/apps/analytics/PipelinedRequester;.addRequest (Lorg/apache/http/HttpEntityEnclosingRequest;)V
D/dalvikvm( 7292): GC_CONCURRENT freed 253K, 47% free 3251K/6023K, external 0K/0K, paused 2ms+3ms
I/dalvikvm( 7292): DexOpt: access denied from Lcom/google/android/apps/analytics/PipelinedRequester; to field Lorg/apache/http/impl/AbstractHttpClientConnection;.metrics
W/dalvikvm( 7292): VFY: unable to resolve instance field 5225
D/dalvikvm( 7292): VFY: replacing opcode 0x54 at 0x0008
D/dalvikvm( 7292): VFY: dead code 0x000a-0090 in Lcom/google/android/apps/analytics/PipelinedRequester;.sendRequests ()V
D/AndroidRuntime( 7292): Shutting down VM
W/dalvikvm( 7292): threadid=1: thread exiting with uncaught exception (group=0x400a7560)
E/AndroidRuntime( 7292): FATAL EXCEPTION: main
E/AndroidRuntime( 7292): java.lang.NoSuchMethodError: org.apache.http.conn.scheme.PlainSocketFactory.<init>

我可以通过设置 !method/propagation/* 来解决这个问题

但是为什么这些问题只出现在禁用混淆的情况下?一个不应该对另一个没有影响吗?

4

1 回答 1

4

混淆节省了您,因为它将您的 Apache HttpClient 类的副本重命名为不会与Android 中已经存在的那些类的副本冲突的名称。

令人讨厌的地方......您可能要考虑根本不使用 Apache HttpClient,并使用 Jesse Wilson 建议的内置HttpURLConnection类:

http://android-developers.blogspot.com/2011/09/androids-http-clients.html

你可以在 HttpURLConnection 上试试这个 Android 友好的面板:

https://github.com/kevinsawicki/http-request

如果您确实必须使用 Apache HttpClient,请使用 Android 中嵌入的旧版本,或者尝试调整您的 ProGuard 配置以混淆HttpClient 库。

于 2012-07-06T23:28:44.977 回答