2

I have an Android application that allows the user to connect to his Facebook account and automatically make a post on his wall.

All this is perfectly working with the debug build (using either the fallback webview dialog or the native application activity). I am using the latest Facebook Connect API for Android.

When testing the release version of the application, I noticed that the fallback webview dialog does not allow to connect to Facebook (after entering the username/password, it shows a standard 404 page that says it could not find the page fbconnect:/success/#access_token=3213546...)

I suspect proguard has stripped some code but I cannot figure out how to determine what is causing the problem. Could anybody give some clues and get me going in the right direction?

My proguard.cfg file contains the following lines to leave Facebook Connect alone:

-keep class com.facebook.android.*
-keepclassmembers public class com.facebook.android.Facebook { 
    public static final *; 
}

In usage.txt I can see the facebook classes, string members, ...

Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124

4 Answers4

3

I fixed it with the following rules (however I am no expert so there might be mistakes in there).

-keep class com.facebook.android.*
-keep class android.webkit.WebViewClient
-keep class * extends android.webkit.WebViewClient
-keepclassmembers class * extends android.webkit.WebViewClient { 
    <methods>; 
} 
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
  • I seem to be having a similar problem... Log shows something about com.facebook.android.FBDialog (obfuscated) and android.webkit.WebViewClient I'm also no expert in ProGuard! Can someone confirm that these rules are ok (not over the top)? Would this do the job? -keep public class com.facebook.** {*;} – Kavi Aug 20 '11 at 20:48
  • 1
    This approach also stops proguard whacking JavaScript interface methods that are only called from the JavaScript in the WebView. Otherwise the Java interface methods are removed by proguard, causing the WebView's JavaScript to not find the method to call into the Java. The program will work perfectly under, say, Eclipse, but will fail silently when built for release. This answer saved countless hours of frustration. – Colin Jan 05 '12 at 20:32
2

This is the only thing that worked for me with facebook sdk 3.0:

-keepattributes Signature

-dontwarn com.facebook.**

-dontwarn com.parse.**

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

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

(got this from http://adilatwork.blogspot.com/2013/01/parse-android-sdk-facebook-and-proguard.html)

berglind0sk
  • 73
  • 1
  • 7
2

I was getting the error Webpage not available fbconnect://success#access_token=... When using an existing app (Draw Something) that connects to facebook. The problem went away when I uninstalled the two different facebook apps i had installed on my phone (Galaxy note 2 with Android 4.1.2) and reinstalled the current facebook app.

Scott
  • 31
  • 1
0

To make facebookConnect work with an android release build you need to create a reference to the keystore file, which you have used for signing your app.

on a mac:

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

on win:

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

the output should be set in Android -> Key Hashes in Facebook settings

webdeb
  • 12,993
  • 5
  • 28
  • 44