使用ProGuard的与Android的Facebook SDK 3.0的错误 [英] Error on using proguard with Android Facebook sdk 3.0
问题描述
警告:我删除了很多旧文本,以保持这一问题更加干净。只是检查历史,如果需要的。
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版本-3.0.2.b标记)。我不使用的JAR文件。相反,我进口的sdk我的工作区中,作为教的<一个href="https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/">documentation.
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.
目前的某一点,在执行时,该应用加载一个<一href="https://developers.facebook.com/docs/reference/android/3.0/PlacePickerFragment">PlacePickerFragment让用户选择他在哪里的地方。为$ C C这个$,我照做了<一href="https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/show-nearby-places/">Scrumptious教程。 当我生成调试APK,而无需使用 ProGuard的
一切正常。但是,当我使用生成签名的APK 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
文件:
-keep class com.facebook.** {
*;
}
我现在的 projet.properties
文件(节选):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
正如你所看到的,我的 ProGuard的
配置该文件的专业化 。
如果我把 -dontobfuscate
在 ProGuard的-project.txt
文件,它会奏效。但我不明白的是,保持类com.facebook。**
应该已经$与Facebook的p $ pvent类被扰乱。这表明该问题没有直接关系,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.
的<一个href="https://github.com/facebook/facebook-android-sdk/blob/sdk-version-3.0.2.b/facebook/src/com/facebook/model/GraphObject.java#L278">excerpt
The excerpt of code that throws com.facebook.FacebookGraphObjectException
is:
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
是空
的发布版本。但在这两个构建(调试和发布) 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.
我怎样才能解决这个问题呢?
How can I fix this problem?
推荐答案
这将解决你的问题,我希望:
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.
这篇关于使用ProGuard的与Android的Facebook SDK 3.0的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!