FB.Init not loaded on my android device

Hello every one, I have a problem when I testing my app on my tablet.
I’m using facebook sdk 6.2.2., Unity 4.6.5.
I have good key hash on unity and my app on Facebook developer.
My app on facebook developer is online for public.
I have th good permission.

But when I have installed my app.apk on my tablet and have ran my app.apk FB.init(SetInit, onHideUnity) isn’t call and the rest is executed. So I can’t use FB.Login, FB.apprequest etc.

How can I fix this ? this problem make me crazy !

Thanks for help.

I have a c# script named “FB.Cs” where there is declaration Init method like this :

public static void Init(
        InitDelegate onInitComplete,
		string appId,
        bool cookie = true,
        bool logging = true,
        bool status = true,
        bool xfbml = false,
        bool frictionlessRequests = true,
        HideUnityDelegate onHideUnity = null,
        string authResponse = null)
    {
        FB.appId = appId;
        FB.cookie = cookie;
        FB.logging = logging;
        FB.status = status;
        FB.xfbml = xfbml;
        FB.frictionlessRequests = frictionlessRequests;
        FB.authResponse = authResponse;
        FB.OnInitComplete = onInitComplete;
        FB.OnHideUnity = onHideUnity;

        if (!isInitCalled)
        {
            var versionInfo = FBBuildVersionAttribute.GetVersionAttributeOfType(typeof (IFacebook));

            if (versionInfo == null)
            {
                FbDebug.Warn("Cannot find Facebook SDK Version");
            }
            else
            {
                FbDebug.Info(String.Format("Using SDK {0}, Build {1}", versionInfo.SdkVersion, versionInfo.BuildVersion));
            }

#if UNITY_EDITOR
            FBComponentFactory.GetComponent<EditorFacebookLoader>();
			#endif
#if UNITY_WEBPLAYER
            FBComponentFactory.GetComponent<CanvasFacebookLoader>();
			#endif
#if UNITY_IOS
            FBComponentFactory.GetComponent<IOSFacebookLoader>();
			#endif
#if UNITY_ANDROID
            FBComponentFactory.GetComponent<AndroidFacebookLoader>();
#endif
//#else
//            throw new NotImplementedException("Facebook API does not yet support this platform");
//#endif
            isInitCalled = true;
            return;
        }

and see :

If it is working in fb canvas and not android the only code related issue I could think of is if you have an platform dependent compilation ‘if’ clauses. Unity - Manual: Conditional Compilation

Is your FB.init inside a clause like this?:

#if UNITY_WEBPLAYER
FB.init(SetInit, onHideUnity);
#endif

This will cause it to only work on the canvas and not with android. Make sure that none of your facebook dependencies are encapsulated like this as well, such as:

#if UNITY_WEBPLAYER
using Facebook.MiniJSON;
#endif

if there, those methods will only run on the web canvas and not android, ios, or anything else.

Other than that I think it must be an error in the configuration of the app in your facebook developer settings, or on the unity editor side with the appid.

I solved my problem, it was the dll who didn’t load, I thus have to delete the files of the plugin Facebook, Example, Facebook and Plugin, and I reimported it in my project and the sdk initializes well. Finally! Thank you for helping in any case.

See you soon.

I faced same problem, working fine in unity editor, but not working in android phone.
I was using game analytics sdk also, so I got two support-version in my Assets folder;

  • 1st one in
    Assets\Plugins\Android\support-v4-24.2.0
  • 2nd one in
    Assets\FacebookSDK\Plugins\Android\libs\support-v4-23.4.0

As not support more than one support-version, I deleted 2nd one.

For me it was the problem, FB.Init() was not working in phone.

When I delete First one and keep the 2nd one, Its worked!!!

for solving the fb.init() method crease while the app is run on the android device then use the namespace where you can create fb_manager script just on the beging of the script use namespace this problem is resolve
i attached my fbmanager script with this review


namespace LoginSplash{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;
public class Fb_Manager : MonoBehaviour {

// Use this for initialization
void Start () {
	
}

// Update is called once per frame
void Update () {
	
}
private void Awake()
{
	if (!FB.IsInitialized)
	{

	FB.Init (this.InitCallback, this.OnHideUnity);
		// Signal an app activation App Event

// FB.Init (() => {
// if (FB.IsInitialized) {
// FB.ActivateApp ();
// Debug.Log (“<color=red>Fb Is Intialised”);
// } else {
// Debug.Log (“<color=red>Fb Is not Intialised”);
// }
//
// },
// isGameShown => {
// if (!isGameShown)
// Time.timeScale = 0;
// else
// Time.timeScale = 1;
// });
}
else
{
FB.ActivateApp ();
Debug.Log(“Failed to Initialize the Facebook SDK”);
}

}
	private void InitCallback()
	{
		if (FB.IsInitialized)
		{
			// Signal an app activation App Event
			FB.ActivateApp ();
			Debug.Log ("<color=red>Fb Is Intialised</color>");
		}
		else
		{
			Debug.Log("Failed to Initialize the Facebook SDK");
		}
	}

	private void OnHideUnity(bool isGameShown)
	{
		if (!isGameShown)
			Time.timeScale = 0;
		else
			Time.timeScale = 1;
	}
public void FacebookLogin()
{
	var permissions = new List<string>() { "public_profile", "email", "user_friends" };
	//FB.LogInWithReadPermissions(permissions, AuthCallback);
	FB.LogInWithReadPermissions(permissions, AuthCallback);
}
private void AuthCallback(ILoginResult result)
{
	if (FB.IsLoggedIn)
	{
		// AccessToken class will have session details
		var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
		// Print current access token's User ID
		Debug.Log(aToken.UserId);
		// Print current access token's granted permissions
		foreach (string perm in aToken.Permissions)            
			Debug.Log(perm); 
		GetName ();
	}
	else
	{
		Debug.Log("User cancelled login");
	}
}
public void FacebookLogout()
{
	FB.LogOut();
}
string Fb_name;
public void GetName()
{
	FB.API("me?fields=name", Facebook.Unity.HttpMethod.GET, delegate (IGraphResult result)
		{
			if (result.ResultDictionary != null)
			{
				foreach (string key in result.ResultDictionary.Keys)
				{
					Debug.Log(key + " : " + result.ResultDictionary[key].ToString());
					if (key == "name")
						//btnName.GetComponentInChildren<Text>().text = result.ResultDictionary[key].ToString();
						Fb_name=result.ResultDictionary[key].ToString();
					Debug.Log("<color=red>Facebook Name</color>"+Fb_name);
				}
			}
		});
}

}
}


this is my script just check and update your script as according their needs
thanks
this will help to the others as well as to needed person
i allways here to give the solution for such type of errors