Facebook SDK for Android Upgrade Guide

Upgrading the Android SDK to 5.0.0 and beyond

  • See facebook/facebook-android-sdk/CHANGELOG.md on GitHub.
  • Change dependencies {} section of your build.gradle (module: app) file to compile the latest version of the Facebook SDK :
  • implementation 'com.facebook.android:facebook-android-sdk:latest.release'

    Upgrading the Android SDK from 4.40.0 to 4.41.0

    No special steps are required to upgrade to 4.41.0.

    Upgrading the Android SDK from 4.39.1 to 4.40.0

    No special steps are required to upgrade to 4.40.0.

    Upgrading the Android SDK from 4.38.1 to 4.39.0

    No special steps are required to upgrade to 4.39.0.

    Upgrading the Android SDK from 4.38.0 to 4.38.1

    No special steps are required to upgrade to 4.38.1.

    Upgrading the Android SDK from 4.37.0 to 4.38.0

    No special steps are required to upgrade to 4.38.0.

    Upgrading the Android SDK from 4.37.0 to 4.37.0

    No special steps are required to upgrade to 4.37.0.

    Upgrading the Android SDK from 4.36.1 to 4.37.0

    No special steps are required to upgrade to 4.37.0.

    Upgrading the Android SDK from 4.36.0 to 4.36.1

    No special steps are required to upgrade to 4.36.1.

    Upgrading the Android SDK from 4.35.0 to 4.36.0

    No special steps are required to upgrade to 4.36.0.

    Upgrading the Android SDK from 4.34.0 to 4.35.0

    No special steps are required to upgrade to 4.35.0.

    Upgrading the Android SDK from 4.33.0 to 4.34.0

    No special steps are required to upgrade to 4.34.0.

    Upgrading the Android SDK from 4.32.0 to 4.33.0

    No special steps are required to upgrade to 4.33.0.

    Upgrading the Android SDK from 4.31.0 to 4.32.0

    No special steps are required to upgrade to 4.32.0.

    Upgrading the Android SDK from 4.30.0 to 4.31.0

    No special steps are required to upgrade to 4.31.0.

    Upgrading the Android SDK from 4.29.0 to 4.30.0

    Account Kit preferences API is deprecated. After upgrading to graph api v1.3 you will not longer be able to store key-value pairs on user preferences.

    Upgrading the Android SDK from 4.28.0 to 4.29.0

    No special steps are required to upgrade to 4.29.0.

    Upgrading the Android SDK from 4.27.0 to 4.28.0

    No special steps are required to upgrade to 4.28.0.

    Upgrading the Android SDK from 4.26.0 to 4.27.0

    Facebook SDK

    • Update any references to GraphRequest.createOpenGraphObject(ShareOpenGraphObject) to ShareGraphRequest.createOpenGraphObject(ShareOpenGraphObject) instead.
    • Update any references to FacebookSDK.[set|get]WebDialogTheme(...) to WebDialog.[set|get]WebDialogTheme(...).

    Account Kit SDK

    No special steps are required to upgrade to 4.27.0.

    Upgrading the Android SDK from 4.25.0 to 4.26.0

    No special steps are required to upgrade to 4.26.0.

    Upgrading the Android SDK from 4.24.0 to 4.25.0

    No special steps are required to upgrade to 4.25.0.

    Upgrading the Android SDK from 4.23.0 to 4.24.0

    No special steps are required to upgrade to 4.24.0.

    Upgrading the Android SDK from 4.22.1 to 4.23.0

    No special steps are required to upgrade to 4.23.0.

    Upgrading the Android SDK from 4.22.0 to 4.22.1

    No special steps are required to upgrade to 4.22.1.

    Upgrading the Android SDK from 4.21.1 to 4.22.0

    Facebook SDK

    The title, description, caption and image field of FBSDKShareLinkContent have been deprecated. Please take appropriate action to remove usage of them.

    Account Kit SDK

    Remove the loginType parameter from constructor of SkinManager when assigning a new UI Manager. When using SkinManager, you no longer need to specify the AppLoginTheme for AccountKitActivity in AndroidManifext.xml.

    Upgrading the Android SDK from 4.21.0 to 4.21.1

    No special steps are required to upgrade to 4.21.1.

    Upgrading the Android SDK from 4.20.0 to 4.21.0

    No special steps are required to upgrade to 4.21.0.

    Upgrading the Android SDK from 4.19.0 to 4.20.0

    No special steps are required to upgrade to 4.20.0.

    Upgrading the Android SDK from 4.18.0 to 4.19.0

    Android SDK

    The Facebook SDK is now auto initialized on Application start. If you are using the Facebook SDK in the main process and don't need a callback on SDK initialization completion you can now remove calls to FacebookSDK.sdkInitialize. If you do need a callback, you should manually invoke the callback in your code.

    Basic App Events are now logged after initializing the Facebook SDK. Calls to activateApp can now be removed from your application. This feature can be disabled by following the instructions in App Events docs.

    The LoginButton UI is changed in 4.19.0. Instead of "Log in with Facebook", the button now displays "Continue with Facebook". The button color is changed to #4267B2 from #3B5998. The button height is decreased from 30dp to 28dp due to use of smaller font size and paddings around a larger Facebook logo.

    The interface for using LoginButton remains the same. Please take time to ensure the updated LoginButton does not break your app's UX

    Account Kit SDK

    The Account Kit SDK is now auto initialized on Application start. If you are using the Account Kit SDK in the main process and don't need a callback on SDK initialization completion you can now remove calls to AccountKit.initialize. If you do need a callback, you should manually invoke the callback in your code.

    Audience Network SDK

    No special steps are required to upgrade to 4.19.0.

    Upgrading the Android SDK from 4.17.0 to 4.18.0

    No special steps are required to upgrade to 4.18.0.

    Upgrading the Android SDK from 4.16.1 to 4.17.0

    If you use Account Kit Advanced UI, make sure to handle the three new screens as noted in the docs.

    Upgrading the Android SDK from 4.16.0 to 4.16.1

    No special steps are required to upgrade to 4.16.1.

    Upgrading the Android SDK from 4.15.0 to 4.16.0

    No special steps are required to upgrade to 4.16.0.

    Upgrading the Android SDK from 4.14.1 to 4.15.0

    Classes and methods associated with App and Game Groups have been deprecated. Please take appropriate action to remove usage of them.

    Upgrading the Android SDK from 4.14.0 to 4.14.1

    No special steps are required to upgrade to 4.14.1.

    Upgrading the Android SDK from 4.13.2 to 4.14.0

    No special steps are required to upgrade to 4.14.0.

    Upgrading the Android SDK from 4.13.1 to 4.13.2

    No special steps are required to upgrade to 4.13.2.

    Upgrading the Android SDK from 4.13.0 to 4.13.1

    No special steps are required to upgrade to 4.13.1.

    Upgrading the Android SDK from 4.12.1 to 4.13.0

    No special steps are required to upgrade to 4.13.0.

    Upgrading the Android SDK from 4.12.0 to 4.12.1

    No special steps are required to upgrade to 4.12.1.

    Upgrading the Android SDK from 4.11.0 to 4.12.0

    No special steps are required to upgrade to 4.12.0.

    Upgrading the Android SDK from 4.10.1 to 4.11.0

    Instead of calling AppEventsLogger.activateApp and AppEventsLogger.deactivateApp in each Activity, you should now just call AppEventsLogger.activateApp(Application) from your Application's onCreate method and the SDK will automatically track sessions for you.

    public class MyApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
            FacebookSdk.sdkInitialize(getApplicationContext());
            AppEventsLogger.activateApp(this);
        }
    }
    

    Note the v4.11 SDK targets v2.6 of the Graph API.

    Upgrading the Android SDK from 4.10.0 to 4.10.1

    No special steps are required to upgrade to 4.10.1.

    Upgrading the Android SDK from 4.9.0 to 4.10.0

    If you relied on graph requests being localized. You now have to specify the locale parameter manually.

    Upgrading the Android SDK from 4.8.2 to 4.9.0

    No special steps are required to upgrade to 4.9.0.

    Upgrading the Android SDK from 4.8.1 to 4.8.2

    No special steps are required to upgrade to 4.8.2.

    Upgrading the Android SDK from 4.8.0 to 4.8.1

    No special steps are required to upgrade to 4.8.1.

    Upgrading the Android SDK from 4.7.0 to 4.8.0

    No special steps are required to upgrade to 4.8.0.

    Upgrading the Android SDK from 4.6.0 to 4.7.0

    The SDK now targets v2.5 of the Graph API. Please review the Graph API changelog for details.

    The GameRequestContent 'to' member has been deprecated and replaced with Recipients.

    Upgrading the Android SDK from 4.5.1 to 4.6.0

    The SDK now requires a minimum sdk of API level 15 or above.

    Upgrading the Android SDK from 4.5.0 to 4.5.1

    No special steps are required to upgrade to 4.5.1.

    Upgrading the Android SDK from 4.4.1 to 4.5.0

    No special steps are required to upgrade to 4.5.0.

    Upgrading the Android SDK from 4.4.0 to 4.4.1

    No special steps are required to upgrade to 4.4.1.

    Upgrading the Android SDK from 4.3.0 to 4.4.0

    The SDK now targets v2.4 of the Graph API. Please review the Graph API changelog for details. For example, the number of default fiends returned by Graph endpoints have been reduced and you should always explicitly ask for the fields you need.

    Upgrading the Android SDK from 4.2.0 to 4.3.0

    No special steps are required to upgrade to 4.3.0.

    Upgrading the Android SDK from 4.1.2 to 4.2.0

    The method to set the custom request code for the login button has been removed.

    Upgrading the Android SDK from 4.1.1 to 4.1.2

    No special steps are required to upgrade to 4.1.2.

    Upgrading the Android SDK from 4.1.0 to 4.1.1

    No special steps are required to upgrade to 4.1.1.

    Upgrading the Android SDK from 4.0.1 to 4.1.0

    There is one breaking change from 4.0.

    Style attr tags are now namespaced to avoid conflicts. Apps will need to add the namespace "com_facebook_" to their existing facebook sdk style attrs.

    For example.

    facebook:preset_size="small"

    becomes

    facebook:com_facebook_preset_size="small"

    Upgrading the Android SDK from 4.0 to 4.0.1

    No special steps are required to upgrade to 4.0.1.

    Upgrading the Android SDK from 3.x to 4.x

    The Facebook SDK for Android v4.0 is a major version upgrade which features:

    • Improved login programming model.
    • Improved sharing programming model, and more ways to share without needing an access token.
    • Improved error handling and error recovery mechanism.
    • The SDK now allows developers to run ProGuard across the entire project, reducing the footprint in the final APK.

    Install and Setup Updates

    For full instructions on install and setup for 4.x, see Getting Started Android SDK.

    • Set up the app ID in AndroidManifest.xml as in 3.x

    • If you use any native dialogs such as Share or Invite add your app name to AndroidManifest.xml:

    <meta-data android:name="com.facebook.sdk.ApplicationName"
               android:value="@string/app_name" 
    • LoginActivity is replaced by FacebookActivity. Add this in AndroidManifest.xml:
    <activity android:name="com.facebook.FacebookActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
              android:label="@string/app_name" />
    • To initialize the SDK, call FacebookSdk.sdkInitialize from onCreate in Activity or Application:
    @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         FacebookSdk.sdkInitialize(this.getApplicationContext());
    }
    • See FacebookSdk class for other configurations you can set at app launch.

    Login Updates

    For more information on Login in 4.x, also see Facebook Login for Android.

    • Session Removed - AccessToken, LoginManager and CallbackManager classes supercede and replace functionality in the Session class.

    • Access Tokens - You can load AccessToken.getCurrentAccessToken with the SDK from cache or if the app is cold launched from an app bookmark. For instructions, see Facebook Login for Android, Get Current Token.

    • Login Button - The easiest way to add Login is to use the LoginButton in 4.x. See Facebook Login for Android, Add Facebook Login.

    • UserSettingsFragment class has been removed from the SDK.

    • LoginManager is a singleton instance, and works with the AccessToken's currentAccessToken. After login the SDK sets currentAccessToken. To get additional permissions call the logInWith... methods.

    • LogInWith... methods always open a prompt UI if necessary. There's no equivalent to the Session.openActiveSessionFromCache or Session.OpenActiveSession(Activity, boolean, StatusCallback). Instead, you should check AccessToken.getCurrentAccessToken() at onCreate(), and if not null, skip login.

    • AccessToken broadcast events when it is set, unset or updated. Use the AccessTokenTracker to receive these events. See Facebook Login for Android, Track Access Tokens.
    • currentAccessToken automatically caches when the SDK sets it.
    • ProfileTracker.getCurrentProfile returns the current logged in user.
    • ProfileTracker returns events if the logged in user changes. see Facebook Login for Android, Track Current Profile.
    • CallbackManager.onActivityResult replaces Session.onActivityResult and UiLifecycleHelper.onActivityResult. See Facebook Login for Android, Register a Callback.

    Graph API Updates

    For more information on Android and Graph API in 4.x, also see Using the Graph API, Android.

    • Request and Response classes in v3 are now called GraphRequest and GraphResponse.
    • Methods and constructors that used to take Session in v3 now take AccessToken or implicitly use AccessToken.getCurrentAccessToken if you don't provide one.
    • Methods like newMeRequest, newMyFriendsRequest returned a typed parameter in the callback like GraphUser or List<GraphUser> now pass in generic JSONObject and JSONArray instead.

    The old version:

    Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
          @Override
            public void onCompleted(GraphUser user, Response response) {
                if (user != null) {
                    profilePictureView.setProfileId(user.getId());
                }
            }
    }).executeAsync();

    The new version

    GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject user, GraphResponse response) {
                if (user != null) {
                    profilePictureView.setProfileId(user.optString("id"));
                }
            }
    }).executeAsync();
    • FacebookRequestError class has more error handling information. See Using the Graph API, Android.
    • Graph API calls now also have the ability to pass back debug information for developers during testing. You can set the LoggingBehavior.GRAPH_API_DEBUG_WARNING or LoggingBehavior.GRAPH_API_DEBUG_INFO flags in the FacebookSdk class.

    Sharing Updates

    For more information on Android and Sharing in 4.x, also see Sharing on Android.

    • Content Model - Each dialog can show a Content object which represents the data for that dialog. For example AppInvitesDialog shows the AppInvitesContent. Each Content class also has a corresponding Builder to help you build the content object. These are in the com.facebook.share.model package. See Sharing on Android, Modeling Content.
    • Dialog Classes - There are now individual Dialog classes for every type of dialog that Facebook offers. They are in the com.facebook.share.widget package. See Sharing on Android, Add Sharing UIs.
    • Feed Dialog - Instead of using the Feed Dialog directly (via WebDialog.FeedDialogBuilder in v3.x), you should now use ShareDialog, which will use the native Share Dialog in the Facebook app if installed, and fall back to a webview. If you explicitly want to show only the Feed Dialog, you can use ShareDialog.show(content, ShareDialog.Mode.FEED);
    • Buttons - There are also the SendButton and ShareButton which are drop-in replacement buttons for the MessageDialog and ShareDialog respectively.

    App Events Updates

    No major API changes, but classes are now in com.facebook.appevents.