Search code examples
androidfacebookproguardfacebook-android-sdkfacebook-share

Proguard removed Facebook Sdk Share Dialog Content


I am using proguard with my android project. Whenever i open a share dialog of Facebook for Android it gets empty.

facebook sdk version is 3.23.1

if(FacebookDialog.canPresentShareDialog(thisObj, FacebookDialog.ShareDialogFeature.SHARE_DIALOG)){
    OpenGraphObject object = OpenGraphObject.Factory.createForPost("namespace:"+obj.object);
    object.setProperty("title", obj.title);
    object.setProperty("image", obj.image);
    object.setProperty("url", obj.url);
    object.setProperty("description", obj.description);
    OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
    action.setType("namespace:"+obj.action);
    action.setProperty(obj.object, object);
    FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(thisObj, action, obj.object).build();
    fbUiLifecycleHelper.trackPendingDialogCall(shareDialog.present());
}

this code works perfect when using it without proguard, everything is shared easily, i also submitted Key Hashes on Facebook correctly for different signatures used.

Whenever i use Proguard obuscation, I get empty title, image or description in the sharedialog, all data gets lost and sometimes it says error and sometimes closes without error

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

-keepattributes Signature

i also used many proguard tags including these ones, but the only case when the share dialog works perfectly is when i disable obfuscation by tag "-dontobfuscate".

Hope somebody had similar issue and can help me.

Sometimes log displays errors like Serialization error, i also tried many codes from proguard official site, like the following but this never solved the issues, its been 2 days since i am searching questions on stackoverflow and compiled the apk file using various proguard options.

-keepnames class * implements java.io.Serializable

-keepclassmembernames 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();
}

Solution

  • The Older Facebook Sdk was giving errors with proguard. Now the new Facebook Sdk versions 4.0.0 and 4.0.1 are not giving any errors with proguard. But for using the new sdk i have updated the following 1) Eclipse is not officially supported by Android so migrated to Android Studio. 2) used the facebook sdk as a Gradle Dependency not as a project(like we did in Eclipse or older versions of sdk). No need to import any project, just add this line to gradle depedencies

    compile "com.facebook.android:facebook-android-sdk:4.0.1"
    

    thats it, after these changes proguard worked smoothly without errors, but surely i had a lot of migration issues. Good Luck