Error : Cannot find Facebook SDK Version

夙愿已清 提交于 2019-12-08 11:26:08

问题


the SDK 7.x is not working on Unity 5.1.0f3 , i always got the error version not found . does someone have see this error ?


回答1:


Actually, it's just a warning. But you can fix it.

There are several places where facebook plugin calls

FBBuildVersionAttribute.GetVersionAttributeOfType(typeof(AbstractFacebook));

So first, you need to modify FBBuildVersionAttribute to this:

// we are going to apply this attribute to Class
// instead of Assembly
// also make it inheritable for all implementations
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
public class FBBuildVersionAttribute : Attribute
{
    private DateTime buildDate;
    private string buildHash;
    private string buildVersion;

    private string sdkVersion;

    public DateTime Date { get { return buildDate; } }
    public string Hash { get { return buildHash; } }
    public string SdkVersion { get { return sdkVersion; } }
    public string BuildVersion { get { return buildVersion; } }

    public FBBuildVersionAttribute(string sdkVersion, string buildVersion)
    {
        this.buildVersion = buildVersion;
        var parts = buildVersion.Split('.');
        buildDate = DateTime.ParseExact(parts[0], "yyMMdd", System.Globalization.CultureInfo.InvariantCulture);
        buildHash = parts[1];

        this.sdkVersion = sdkVersion;
    }

    public override string ToString()
    {
        return buildVersion;
    }

    public static FBBuildVersionAttribute GetVersionAttributeOfType(Type type)
    {
        foreach (FBBuildVersionAttribute attribute in getAttributes(type))
        {
            return attribute;
        }
        return null;
    }

    private static FBBuildVersionAttribute[] getAttributes(Type type)
    {
        if (type == null)
            throw new ArgumentNullException("type");

        // we want to get attributes from type instead of assmebly
        return (FBBuildVersionAttribute[])(type.GetCustomAttributes(typeof(FBBuildVersionAttribute), false));
    }
}

No you just need to add this attribute to AbstractFacebook:

[FBBuildVersionAttribute("7.0.1", "150604.98558e55096475c")]
public abstract class AbstractFacebook : MonoBehaviour
{
    // ...
}

Note that 98558e55096475c part is trash string. It's not actual build hash, cause I don't have one.




回答2:


Get the latest version of the FB Unity SDK. Change log says it's fixed now.

https://developers.facebook.com/docs/unity/change-log



来源:https://stackoverflow.com/questions/30806008/error-cannot-find-facebook-sdk-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!