Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Conflict Between Official Facebook & Admob SDKs?

Discussion in 'Android' started by p_barlow1, Feb 16, 2016.

  1. p_barlow1

    p_barlow1

    Joined:
    Nov 23, 2015
    Posts:
    2
    Hi,

    First post so go easy please :)

    I'm 3 months in to my first game and would have it finished this week if it wasn't for a strange problem I'm having when trying to show ads using the official Admob SDK. I'm using the latest versions of the Facebook and Admob plugins with Unity 5.2.3f1

    In the Start method my my intro scene I load a banner advert to display along the bottom. bannerView is a public variable of type GoogleMobileAds.API.BannerView:-

    if (HasConnection())
    {

    if (bannerView == null)
    {

    bannerView = new BannerView("********", AdSize.SmartBanner, AdPosition.Bottom);
    bannerView.LoadAd(createAdRequest());
    }
    else
    {
    bannerView.Show();
    }
    }
    }

    Nice and simple, after a few seconds a banner displays as expected. If I leave it the banner refreshes every 30 seconds and all is well with the world. From that same scene the player has the option of signing in to Facebook to save high scores, compete with friends etc This is all done using the Facebook SDK for Unity. I'm currently testing this on an Android device without the Facebook app installed so the login prompt for Facebook appears as what looks like a webview overlay. No matter how I exit that Facebook login, be it cancelling or signing in the next time that bannerView goes to refresh it crashes the app. If I don't pop up the Facebook sign in then it will sit happily refreshing adverts every 30 seconds with no issues. If I load the main game scene, die, then reload the intro scene it works as expected. If I am already signed in to Facebook when I start the game then it works, the adverts refresh without a problem. There is something about showing the Facebook login prompt that causes a problem with Admob loading an advert.

    I've looked at the manifest and it appears as though the relevant admob, Facebook info is being included (I assume if there was a problem with the manifest it simply wouldn't work at all?) I've tried hiding/destroying the banner before calling the Facebook login and then Showing it afterwards. I've tried loading the intro scene again after the Facebook login returns (it crashes instantly) Nothing seems to work. The very first time that bannerView tries to load an ad after the Facebook login it crashes.

    Here's the Facebook code

    if (!FB.IsInitialized)
    {
    FB.Init(InitCallback, onHideUnity);
    }
    else
    {
    FB.ActivateApp();
    if (FB.IsLoggedIn)
    {
    PlayerPrefs.SetInt("IsFaceBookScore", 1);
    thisCamera.GetComponent<IntroInitialise>().AlterText();
    }
    else
    {
    LoginFB();
    }
    }

    private void InitCallback()
    {
    if (FB.IsInitialized)
    {
    FB.ActivateApp();
    if (!FB.IsLoggedIn)
    {
    LoginFB();
    }
    else
    {
    PlayerPrefs.SetInt("IsFaceBookScore", 1);
    thisCamera.GetComponent<IntroInitialise>().AlterText();
    }
    }
    else {
    PlayerPrefs.SetInt("IsFaceBookScore", 0);
    thisCamera.GetComponent<IntroInitialise>().AlterText();
    }
    }

    void LoginFB()
    {
    FB.LogInWithReadPermissions(new List<string>() { "user_friends" }, LoginCallback);
    }

    void LoginCallback(ILoginResult result)
    {
    if (FB.IsLoggedIn)
    {
    PlayerPrefs.SetInt("IsFaceBookScore", 1);
    thisCamera.GetComponent<IntroInitialise>().AlterText();
    }
    else {
    PlayerPrefs.SetInt("IsFaceBookScore", 0);
    thisCamera.GetComponent<IntroInitialise>().AlterText();
    }
    }

    After 6 days going around in circles with this I'm open to any ideas or would love to know if anybody has experienced the same?

    Thanks,
    Paul
     
  2. p_barlow1

    p_barlow1

    Joined:
    Nov 23, 2015
    Posts:
    2
    After over a week of messing around with this I finally came across the solution, don't build in debug mode. For some reason it causes the above problem. Simply by switching to release builds it went away.
     
    ThinhHB likes this.
  3. hameed-ullah-jan

    hameed-ullah-jan

    Joined:
    Sep 24, 2014
    Posts:
    7
    Maybe it's too late to answer, I was facing the same issue, I created a plugin this plugin contains Facebook SDK+Admob+unityads +unity IAP, all of them work together, I've created this plugin in unity 5.6.0, but I've checked it, it is working fine in unity 2017 as well, there is a scene "DemoScene", just open it everything is implemented, unity ads, admob, facebook share with callback, unityIAP.

    Note: before importing the plugin kindly delete all the old plugins, also go to services and turn on unity ads.

    http://www.mediafire.com/file/ccvj7...UnityAds_Plugin_Hameed_Ullah_jan.unitypackage