Finding What the Android Facebook SDK Version Is
Asked Answered
P

4

21

How do I find out the version of the current SDK is installed or referenced by my application? I have looked through the class files and the manifest but there is no reference as to what version it is.

Thanks in advance.

Pollock answered 7/10, 2013 at 13:48 Comment(0)
N
34

You have FacebookSdkVersion class with the current version: https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/FacebookSdkVersion.java

final class FacebookSdkVersion {
    public static final String BUILD = "3.5.2";
    public static final String MIGRATION_BUNDLE = "fbsdk:20130708";
}

Since this class is without modifier and you can't access it from your package, use a reflection. This will return you the sdk version:

private String getFacebookSDKVersion()
{
    String sdkVersion = null;
    ClassLoader classLoader = getClass().getClassLoader();
    Class<?> cls;
    try
    {
        cls = classLoader.loadClass("com.facebook.FacebookSdkVersion");
        Field field = cls.getField("BUILD");
        sdkVersion = String.valueOf(field.get(null));
    }
    catch (ClassNotFoundException e)
    {
        // error
    }
    catch (NoSuchFieldException e)
    {
        // error
    }
    catch (IllegalArgumentException e)
    {
        // error
    }
    catch (IllegalAccessException e)
    {
        // error
    }
    return sdkVersion;
}
Nga answered 7/10, 2013 at 16:35 Comment(0)
C
7

The most easy way:

1.- Go to your AndroidManifest.xml

2.- Look at your Bottom Navigation View, there is two tabs: Text and Merged Manifest, click on the last one.

3.- On the right side will appear the Manifest Sources, there it is: for example i have this: facebook-android-sdk:4.20.0 manifest.

I know its a bit old, but i searched this in march of 2017 and there is no an easy answer like this.

Comfort answered 26/3, 2017 at 19:27 Comment(1)
This worked perfect for me. Thanks! Just note: This is from Android Studio specifically.Jejunum
I
1

There is a public API:

import com.facebook.Settings;

Settings.getSdkVersion()

"Gets the current version of the Facebook SDK for Android as a string."

I don't recommend using reflection to access the package class - they may change that in the future and break your code, but this public API should be considered stable.

Infectious answered 29/9, 2014 at 20:41 Comment(1)
I do not see the settings library available. I am using it for the first time and I really need help to know my FB sdk versionNeotropical
B
0

Late to answer but I found one more class while trying @sromku's answer.

There is one class called FacebookSdk: import com.facebook.FacebookSdk;

It exposes 2 useful methods which we can try:

  1. getGraphApiVersion()
  2. getSdkVersion()
Budge answered 5/8, 2020 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.