嫌为Android使用ProGuard时失败 [英] smack for android fails when using proguard

查看:491
本文介绍了嫌为Android使用ProGuard时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是嫌库(4.1.2)在我的Andr​​oid应用程序连接到XMPP服务器。它完美地运行良好时,code不是缩小的(即使用ProGuard)。但是在释放模式,启用ProGuard的,应用程序只要它连接到服务器崩溃。

I am using the smack library (4.1.2) in my Android app to connect to an XMPP server. It runs perfectly well when the code is NOT minified (ie with proguard). But in release mode, with proguard enabled, the app crashes as soon as it connects to the server.

我想保持unminified这里建议所有相关咂嘴类:<一href=\"http://stackoverflow.com/questions/29678908/what-are-the-recommended-proguard-rules-for-smack-4-1\">What对于拍击4.1推荐ProGuard的规则是什么?

I am trying to keep all relevant smack classes unminified as suggested here: What are the recommended ProGuard rules for Smack 4.1?

-keep class org.jivesoftware.smack.** { *; }
-keep class org.jivesoftware.smackx.** { *; }

但对我来说这是行不通的。下面是崩溃的堆栈跟踪。

But for me this doesn't work. Below is the crash stack trace.

 java.lang.ExceptionInInitializerError
  at org.jivesoftware.smackx.privacy.PrivacyListManager.<init>(PrivacyListManager.java:126)
  at org.jivesoftware.smackx.privacy.PrivacyListManager.getInstanceFor(PrivacyListManager.java:210)
  at org.jivesoftware.smackx.privacy.PrivacyListManager$1.connectionCreated(PrivacyListManager.java:81)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.initConnection(XMPPTCPConnection.java:636)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:834)
  at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:365)
  ...
 Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
  at org.jivesoftware.smack.filter.FlexibleStanzaTypeFilter.<init>(FlexibleStanzaTypeFilter.java:40)
  at org.jivesoftware.smackx.privacy.filter.SetActiveListFilter.<init>(SetActiveListFilter.java:27)
  at org.jivesoftware.smackx.privacy.filter.SetActiveListFilter.<clinit>(SetActiveListFilter.java:25)

在什么ProGuard配置文件将解决这个问题的任何想法?

Any ideas on what proguard config would fix this?

更新:我已经提到的其他问题,我的报告,并解释说,提出的解决方案是不是在这种情况下,修复

Update: I already referred to the other issue in my report and explained that proposed solution is not a fix in this case.

更新2:我已经再生启用行号的堆栈跟踪

Update 2: I have regenerated the stack trace with line numbers enabled.

推荐答案

于是,我找到了解决办法。真不敢相信我花了一整天的时间对这个问题!希望这样可以节省别人同样的问题:

So, I found a solution. Can't believe I spend a whole day on this problem! Hope this saves someone else the same trouble:

引起问题(在咂嘴库)的线是

The line causing the problem (in smack library) is

stanzaType = (Class<S>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];

请注意投。这个问题似乎是默认的ProGuard失去对某些类型的信息,即使已指定-keep为您的类。有用的信息的关键位是在这里:
<一href=\"http://stackoverflow.com/questions/20072703/field-getgenerictype-returns-instance-of-java-lang-class-instead-of-type\">Field.getGenericType()返回java.lang.Class的,而不是类型实例

Note the cast. The problem appears to be the proguard by default looses some information on types, even if you have specified "-keep" for your classes. The crucial bit of helpful information is here: Field.getGenericType() returns instance of java.lang.Class instead of Type

在回答我的问题,因此是下面的ProGuard配置是必需的:

The answer to my question is therefore that the following proguard config is required:

-keepattributes Signature
-keep class org.jivesoftware.smack.** { *; }
-keep class org.jivesoftware.smackx.** { *; }

这篇关于嫌为Android使用ProGuard时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆