使用安卓Facebook sdk 3.0的proguard错误 [英] Error on using proguard with Android Facebook sdk 3.0

查看:131
本文介绍了使用安卓Facebook sdk 3.0的proguard错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告:我删除了很多旧文字,使问题更加干净。只需检查历史记录即可。

Warning: I removed a lot of "old text" to keep the question more clean. Just check the history if needed.

我正在使用 proguard 来缩小和混淆使用 facebook sdk 3.0 (我使用 sdk-version-3.0.2.b标签)。我没有使用JAR文件。相反,我将sdk导入我的工作区,如文档

I'm using proguard to both shrink and obfuscate an app that uses the facebook sdk 3.0 (I'm using the sdk-version-3.0.2.b tag). I'm not using a JAR file. Instead, I imported the sdk inside my workspace, as taught by the documentation.

在执行的某个时刻,应用程序加载一个 PlacePickerFragment 让用户选择他所在的地方。为了编写这个,我完全遵循 Scrumptious tutorial 当我生成调试apk而不使用 proguard 时,所有内容都可以正常工作。但是,当我使用 proguard ,当PlacePickerFragment加载附近的地点时,会出现以下痕迹:

At a certain point in the execution, the app loads a PlacePickerFragment to let the user choose the place where he is. To code this, I follow exactly the Scrumptious tutorial. When I generate the debug apk without using proguard everything works as expected. But when I generate the signed apk using proguard, it crashes when the PlacePickerFragment loads nearby places with the following trace:

E/AndroidRuntime(27472): FATAL EXCEPTION: main
E/AndroidRuntime(27472): com.facebook.FacebookGraphObjectException: can't infer generic type of: interface com.facebook.model.GraphObjectList
E/AndroidRuntime(27472):    at com.facebook.model.GraphObject$Factory.coerceValueToExpectedType(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.model.GraphObject$Factory$GraphObjectProxy.proxyGraphObjectGettersAndSetters(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.model.GraphObject$Factory$GraphObjectProxy.invoke(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.widget.$Proxy2.getData(Native Method)
E/AndroidRuntime(27472):    at com.facebook.widget.GraphObjectPagingLoader.addResults(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.widget.GraphObjectPagingLoader.requestCompleted(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.widget.GraphObjectPagingLoader.access$1(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.widget.GraphObjectPagingLoader$2.onCompleted(Unknown Source)
E/AndroidRuntime(27472):    at com.facebook.Request$4.run(Unknown Source)
E/AndroidRuntime(27472):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(27472):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(27472):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(27472):    at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(27472):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27472):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(27472):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
E/AndroidRuntime(27472):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
E/AndroidRuntime(27472):    at dalvik.system.NativeStart.main(Native Method)

为了避免这个错误,我把所有的Facebook类保持不变,但没有起作用。我目前的 proguard-project.txt 文件:

Trying to avoid this error, I kept all facebook classes untouched, but didn't work. My current proguard-project.txt file:

-keep class com.facebook.** {
   *;
}

我目前的 projet.properties file(摘录):

My current projet.properties file (excerpt):

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

如您所见,我的 proguard 配置是此文件的专业化。

As you can see, my proguard configuration is a "specialization" of this file.

如果我在 proguard-project.txt 文件中放入 -dontobfuscate 它会工作。但是我不明白的是,保持类com.facebook。** 应该已经阻止与facebook相关的类被模糊。这表明问题与facebook类没有直接关系。

If I put -dontobfuscate in proguard-project.txt file, it will work. But what I don't understand is that the keep class com.facebook.** should already prevent classes related to facebook to be obfuscated. Which suggests that the problem is not directly related to the facebook classes.

摘录代码,抛出 com.facebook.FacebookGraphObjectException 是:

static <U> U coerceValueToExpectedType(Object value, Class<U> expectedType, 
        ParameterizedType expectedTypeAsParameterizedType) {

    // [...]

    } else if (Iterable.class.equals(expectedType) || Collection.class.equals(expectedType)
        || List.class.equals(expectedType) || GraphObjectList.class.equals(expectedType)) {
        if (expectedTypeAsParameterizedType == null) {
            throw new FacebookGraphObjectException("can't infer generic type of: " + expectedType.toString());
        }
    // [...]
}

显然,在发布版本中, expectedTypeAsParameterizedType null 。但是在两个版本(调试和发布)中, expectedType 是一个 com.facebook.model.GraphObjectList 接口。不幸的是,我几乎不了解Java反射概念。

Clearly, expectedTypeAsParameterizedType is null in release build. But in both builds (debug and release) expectedType is a com.facebook.model.GraphObjectList interface. Unfortunately, I don't understand almost nothing about Java reflection concepts.

我如何解决这个问题?

推荐答案

这将解决您的问题,我希望:

This will solve your problem, i hope:

胜利者是...

And the winner is .....

-keepattributes Signature

从Proguard主页:

From Proguard Homepage:


签名属性需要能够访问通用的
类型在JDK 5.0及更高版本中进行编译。

The "Signature" attribute is required to be able to access generic types when compiling in JDK 5.0 and higher.

这篇关于使用安卓Facebook sdk 3.0的proguard错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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