Search Unity

Different Firebase configs for different build targets through UCB

Discussion in 'Unity Build Automation' started by ocasta, Jun 13, 2017.

  1. ocasta

    ocasta

    Joined:
    Aug 4, 2016
    Posts:
    2
    I need set up a Unity project that will build with a different Firebase GoogleService-Info.plist file for different target builds through UCB.

    The aim is to build to development and live targets with firebase config files that match the different bundle IDs and Firebase projects.

    I have tried replacing the plist file within the Assets folder with a target specific file held in the repo (not in Assets) in a pre export process but this doesn't appear to work. Unity support have suggested this should work but if anyone has this process working and can help that'd be much appreciated!
     
  2. jauboux

    jauboux

    Joined:
    Dec 3, 2015
    Posts:
    5
    Hi, we might have the exact same need in the future, and I'd be happy to help on the subject and share my results, but I can't get firebase (analytics) to work properly with UCB on ios platform. could you please post your full configuration : Unity version/xcode version/ios resolver settings/.... and tell me how you managed to do it ?
    I've tried all possible ways , with/without cocoapods (with post process script to "manually" solve dependencies), I'm tesing right now the new 4.0 sdk with cocoapods, and though Unity now supports xcworkspace in build & run, UCB still uses the .xcodeproj which gives link errors. I didn't manage to propagate the "add cocoapods to the XCode project" setting, because to my knowledge it is not saved in the project (thus not version controlled)
     
    Last edited: Jun 13, 2017
  3. jauboux

    jauboux

    Joined:
    Dec 3, 2015
    Posts:
    5
    by the way, I did manage to build a minimal sample app with firebase analytics in UCB with a POST export script :

    if (!File.Exists(path + "/GoogleService-Info.plist"))
    {
    FileUtil.CopyFileOrDirectory("Assets/GoogleService-Info.plist", path + "/GoogleService-Info.plist");
    }
    string guid = proj.AddFile("GoogleService-Info.plist", "GoogleService-Info.plist");
    proj.AddFileToBuild(target, guid);


    you might get it to work by having several configs and renaming the good one while copying it to the xcode project's path
    let me know if you're missing the rest of the post export script
     
  4. ocasta

    ocasta

    Joined:
    Aug 4, 2016
    Posts:
    2
    Hi jauboux,

    Not sure if you're still having issues but I've now managed to get this working for targets through UCB.

    In terms of just getting Firebase to work through UCB I found this https://github.com/googleads/googleads-mobile-unity/issues/333 very useful. You disable pods completely through the resolver settings, add them manually from here (https://firebase.google.com/docs/ios/setup#frameworks) and run post processes similar to what you have above.

    Adding the "&& !UNITY_CLOUD_BUILD" to the dependencies methods is important in case that's something you have missed. I had to do this within AppDeps.cs and MessagingDeps.cd within Firebase/Editor in order to get Cloud Messaging to work but may only be AppDeps for Analytics. You'll need to amend this each time you update the plugin.

    For changing Firebase config for different targets I used both pre and post export methods as the plist for iOS (and json and xml for Android) files need to be moved pre export. I created target specific methods and called them from the UCB Advanced settings for each target (I had previously used custom defines for the targets but they weren't accessible at pre export as far as I could tell).