Android ProGuard settings for Facebook

2022-09-01 12:26:43

我终于找到了为什么我的应用程序崩溃了。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 手动添加的命令:

-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}

答案 1

固定:

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

而不是:

-keepattributes Signature
-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient { 
    <methods>; 
}

另外,请务必在Facebook应用程序设置中检查您的哈希键。


答案 2

在我的情况下,您的解决方案

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

作品,但我不得不保留

-keepattributes Signature

为了让一切正常运转。


推荐