Search Unity

Set "Enable Bitcode" default value when building for iOS

Discussion in 'iOS and tvOS' started by Freaking-Pingo, Sep 7, 2015.

  1. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    Hi Uniteers, I have switched to XCode Beta version 7.0 Beta 6 and whenever I am building to iOS i have to manually set the "Enable Bitcode" from "ON" to "OFF" otherwise I can't deploy the build. Is there a way to set the default value to "OFF" when building or do I have to do some post build processing?
     
  2. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Which Unity version are you on?
    We will be shipping patch release with "off" as default soon.
     
  3. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    I am using Unity 5.1.3f1 Personal
     
  4. abarra

    abarra

    Joined:
    Dec 16, 2013
    Posts:
    3
    Hi Freaking-Pingo,

    Do you get the solution for it? I'm having the same issue in my project.

    Thanks.
     
  5. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    I haven't tested it yet, but a co-worker of mine stated after upgrading to Unity 5.2, bitcode is disabled by default.
     
  6. Umai

    Umai

    Joined:
    Jun 18, 2013
    Posts:
    74
    Bit code is enabled for Unity 4.6 iOS exports... very inconvenient, we can't use bit code yet (lots of 3rd party ad sdks don't support it)... I have to manually disable it with every build. Or find a way to script that part,... like a zillion other parts with every build :-/
     
  7. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    You can use Xcode API in a post process step to disable the bitcode setting.
     
    Umai likes this.
  8. Umai

    Umai

    Joined:
    Jun 18, 2013
    Posts:
    74
    Nice. Didn't know that stuff existed. Will have to remember next time.
     
  9. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Built an iOS Xcode pjt and bit code was enabled. Unity 5.3.1p2. Has this issue been addressed?
     
  10. ezio_auditore

    ezio_auditore

    Joined:
    Nov 29, 2014
    Posts:
    2
    Unity 5.3.1p3 also had bit code enabled by default. is that going to be addressed?
     
  11. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    Unity 5.3 is expected to have Bitcode on by default if you are using IL2CPP scripting backend as it's direction where iOS development is moving in general (it's already mandatory for tvOS submissions).
    If you depend on some specific plugin, which doesn't ship with Bitcode you should reach plugin providers for Bitcode enabled version of plugin.

    P.S. if you see Bitcode being enabled on for Mono backend builds, then it's a bug and please let us know. (I believe fix was done for some patch release already).
     
    User340 likes this.
  12. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    Do you have an example of how to use this? I get into PBXPRoject but at that point I don't know what kind of property to set or what strings to use. Any help would be appreciated.
     
  13. psykojello2

    psykojello2

    Joined:
    Jul 19, 2013
    Posts:
    37
    Here's some example code that seems to use these functions. Let us know if you get it to work and what helped.
     
  14. psykojello2

    psykojello2

    Joined:
    Jul 19, 2013
    Posts:
    37
    This seems to work for me. Will check if it works in a cloud build and I can confirm then:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using UnityEditor.Callbacks;
    5. using System.Collections;
    6. using UnityEditor.iOS.Xcode;
    7. using System.IO;
    8.  
    9. public class BL_BuildPostProcess
    10. {
    11.  
    12.     [PostProcessBuild]
    13.     public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    14.     {
    15.        
    16.         if (buildTarget == BuildTarget.iOS)
    17.         {
    18.             string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    19.            
    20.             PBXProject proj = new PBXProject();
    21.             proj.ReadFromString(File.ReadAllText(projPath));
    22.            
    23.             string target = proj.TargetGuidByName("Unity-iPhone");
    24.            
    25.             proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");
    26.            
    27.             File.WriteAllText(projPath, proj.WriteToString());
    28.         }
    29.     }
    30. }
     
    Fangh likes this.
  15. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Thanks for this, saved me!
     
  16. AshyB

    AshyB

    Joined:
    Aug 9, 2012
    Posts:
    191
    What do you do with this script? Just make a file in your assets folder or add it to a game object or what?

    Ah, put it in your Editor folder and thats it? It works in the cloud build?

    When building in the cloud, you first have to build an IOS project in unity normally? Can't just commit the new file to the repo and expect unity cloud build to work?
     
    Last edited: Mar 31, 2016
  17. Deleted User

    Deleted User

    Guest

    Yeah, just add the file to your editor folder and commit it to the branch that your cloud build is directed.
     
  18. Deleted User

    Deleted User

    Guest

    This works great on my end.

    Follow up question, is there a list of properties we could modify with BuildPostProcess? What I am looking to modify is the Language - Modules of the app to get rid of the inflate errors on cloud build.
     
  19. psykojello2

    psykojello2

    Joined:
    Jul 19, 2013
    Posts:
    37
    Sorry for the late reply! Yes you put it in an Editor folder and it should work.

    When Cloud building you do not need an iOS project. Just point it to your project depot on Git/Mercurial which needs to contain only the Assets and ProjectSettings folders. Do not include the library.

    So easy!

    You might run into build issues later, but this is all you need to get started.
     
  20. psykojello2

    psykojello2

    Joined:
    Jul 19, 2013
    Posts:
    37
    I wish I knew where this list of properties can be found. I've asked around but not found it. Just been picking and choosing code examples.

    Here's what I have so far. Pick and use anything you need!

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.Callbacks;
    4. using System.Collections;
    5. using UnityEditor.iOS.Xcode;
    6. using System.IO;
    7.  
    8. public class BL_BuildPostProcess
    9. {
    10.  
    11.     [PostProcessBuild]
    12.     public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    13.     {
    14.        
    15.         if (buildTarget == BuildTarget.iOS)
    16.         {
    17.             /* .xcodeproj/project.pbxproj */
    18.  
    19.             //Get path to the PBX project
    20.             string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    21.  
    22.             //Read the pbx project
    23.             PBXProject proj = new PBXProject();
    24.             proj.ReadFromString(File.ReadAllText(projPath));
    25.  
    26.             //Get the build target
    27.             string target = proj.TargetGuidByName("Unity-iPhone");
    28.  
    29.             //set ENABLE_BITCODE to false (this shouldn't be required in Unity 5.2+)
    30.             proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");
    31.  
    32.             //Write back out the PBX project
    33.             File.WriteAllText(projPath, proj.WriteToString());
    34.            
    35.             /* Info.plist */
    36.            
    37.             // Read the Info.plist file
    38.             string plistPath = path + "/Info.plist";
    39.             PlistDocument plist = new PlistDocument();
    40.             plist.ReadFromString(File.ReadAllText(plistPath));
    41.            
    42.             // Get root of plist
    43.             PlistElementDict rootDict = plist.root;
    44.             //Set Requires full screen = true. This was needed only with Xcode 9.
    45.             rootDict.SetBoolean("UIRequiresFullScreen",true);
    46.             //Adding background modes for remote notification (For Push notifications - OneSignal)
    47.             var bgModes = rootDict.CreateArray("UIBackgroundModes");
    48.             bgModes.AddString("remote-notification");
    49.  
    50.             //Write out the Info.plist file
    51.             plist.WriteToFile(plistPath);
    52.         }
    53.     }
    54. }
     
  21. kashif-shabbir

    kashif-shabbir

    Joined:
    Feb 13, 2015
    Posts:
    2
    using proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
    instead of proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");
    is more appropriate as for some other properties false will not work. XCODE Proj file uses YES/NO instead of TRUE/FALSE
     
    peterc23 and guneyozsan like this.
  22. gamecakestudios

    gamecakestudios

    Joined:
    Nov 13, 2013
    Posts:
    21
    Just to add to this, because I have been messing around with it recently, if you select a row in xcode, hit cmd+c and then paste into a text editor, you'll see exactly what the property names and value formats should be.
     
    AMNOD likes this.