使用Android和Google API客户端的Proguard

时间:2012-03-05 10:38:35

标签: android proguard google-api-java-client

首先,对不起,如果这个话题已被回答,但我还没找到......

我是Android和Proguard的新手。在开发我的应用程序的最后,我想用proguard减小它的大小,当然。由于我在我的应用程序中使用谷歌api客户端的一些库,我已将它们添加为外部罐。

好吧,我的应用程序正常工作而没有通过proguard步骤,但是当我尝试导出它时,它开始让我头疼。很多警告,我不知道如何跳过或安排。这样的东西:

[2012-03-05 07:20:06 - CollaJoveThreads] Proguard returned with error code 1. See console
[2012-03-05 07:20:06 - CollaJoveThreads] Warning: com.google.common.base.Equivalence: can't find referenced class javax.annotation.Nullable
[2012-03-05 07:20:06 - CollaJoveThreads] Warning: com.google.common.base.Equivalence: can't find referenced class javax.annotation.Nullable
[2012-03-05 07:20:06 - CollaJoveThreads] Warning: com.google.common.base.Equivalence: can't find referenced class javax.annotation.Nullable
[2012-03-05 07:20:06 - CollaJoveThreads] Warning: com.google.common.base.Equivalences$Impl$1: can't find referenced class javax.annotation.Nullable
[2012-03-05 07:20:06 - CollaJoveThreads] Warning: com.google.common.base.Equivalences$Impl$1: can't find referenced class javax.annotation.Nullable

和更相似。

我跟踪了Google开发人员的推荐,并将这些行添加到我的proguard.cfg中:

# Needed by google-api-client to keep generic types and @Key annotations accessed via reflection
-keepclassmembers class * {
  @com.google.api.client.util.Key <fields>;
}

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault,*Annotation*

-dontwarn sun.misc.Unsafe

但它会继续显示所有这些警告消息。当我尝试使用'-dontwarn'选项时,我的应用程序崩溃了。

我已经阅读了这些问题,还有更多:

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:16)

您好我知道通过将jsr305 jar文件添加到您的项目中已经解决了这个问题。然而,我花了一段时间才找到可以找到这个罐子的地方,以及如何处理它。

您可以在here获取此jar的最新版本。下载最新的jar并将其放入libs文件夹,然后将其添加到Eclipse中的构建路径一切都应该是正确的。

这也解决了我所有的问题。