我终于找到了为什么我的应用程序崩溃为发布而构建。ProGuard 确实从我的应用程序中剥离了代码,但我通过在 proguard-android.txt(在 sdk 中找到)中使用 keep 命令手动添加类来防止这种情况发生。
对于 Facebook,我使用:
-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient {
<methods>;
}
但我认为我仍然缺少一些东西。该应用程序现在没有崩溃,但我无法登录 Facebook 并使用 Open Graph。当我在调试模式下构建时,一切正常。
您使用 Facebook 和 Facebook 的 Open Graph 的 proguard 设置是什么?
编辑
这是我为 ProGuard 手动添加的命令:
-dontwarn android.support.**
# ActionBarSherlock
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
# Keep line numbers to alleviate debugging stack traces
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keepclassmembers class * implements java.io.Serializable
{
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient {
<methods>;
}
编辑 2 所以没有登录的问题是我使用了我的调试哈希键而不是我的发布哈希键。在我的应用程序设置(developers.facebook.com)中更改了它,发现我的应用程序最终登录但登录后崩溃。
不知道这是否仍然是 ProGuard 问题,但它返回了此错误:
04-02 11:47:31.815: E/AndroidRuntime(9093): FATAL EXCEPTION: main
04-02 11:47:31.815: E/AndroidRuntime(9093): com.facebook.ab: com.facebook.b.e got an unexpected method signature: public abstract com.facebook.b.b com.facebook.b.b.a(java.lang.Class)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.facebook.b.f.a(SourceFile:400)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.facebook.b.e.b(SourceFile:546)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.facebook.b.e.invoke(SourceFile:470)
04-02 11:47:31.815: E/AndroidRuntime(9093): at $Proxy1.a(Native Method)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.facebook.bb.a(SourceFile:124)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.facebook.ar.a(SourceFile:264)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.facebook.as.run(SourceFile:1240)
04-02 11:47:31.815: E/AndroidRuntime(9093): at android.os.Handler.handleCallback(Handler.java:615)
04-02 11:47:31.815: E/AndroidRuntime(9093): at android.os.Handler.dispatchMessage(Handler.java:92)
04-02 11:47:31.815: E/AndroidRuntime(9093): at android.os.Looper.loop(Looper.java:137)
04-02 11:47:31.815: E/AndroidRuntime(9093): at android.app.ActivityThread.main(ActivityThread.java:4931)
04-02 11:47:31.815: E/AndroidRuntime(9093): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 11:47:31.815: E/AndroidRuntime(9093): at java.lang.reflect.Method.invoke(Method.java:511)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-02 11:47:31.815: E/AndroidRuntime(9093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
04-02 11:47:31.815: E/AndroidRuntime(9093): at dalvik.system.NativeStart.main(Native Method)
04-02 11:47:31.820: W/ActivityManager(2130): Force finishing activity com.xxxxx.xxxx/com.xxxxx.views.MainActivity
04-02 11:47:32.360: W/ActivityManager(2130): Activity pause timeout for ActivityRecord{4289ca58 com.xxxxx.xxxxx/com.xxxxx.xxxxx.MainActivity}