Skip to content
Advertisement

Android ProGuard settings for Facebook

I finally found out why my app crashes built for release. ProGuard was indeed stripping code from my application but i prevented this by manually adding the classes with the keep command in the proguard-android.txt (found in the sdk).

For Facebook I used:

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

But I think I’m still missing something. The app is crash free now but I can’t log in to Facebook and use Open Graph. When I built in debug mode this all works fine.

What are your proguard settings for using Facebook and Facebook’s Open Graph?

EDIT

This are my manually added commands for 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>; 
}

EDIT 2 So the problem for not logging in was that I used my debug hash key instead of my release hash key. Changed that in my app settings (developers.facebook.com) and found out that my app finally logs in but crashes after login.

Dont know if this still is a ProGuard problem but it returned this error:

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}

Advertisement

Answer

fixed:

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

instead of:

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

Also be sure to check your hash key in your facebook app settings.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement