Search Unity

Disable Bitcode in project as post processor

Discussion in 'Editor & General Support' started by multimediamarkers, Sep 11, 2020.

  1. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    44
    Hi there,

    I am trying to set for a Xcode project the enable bitcode to "NO". I found this script and it is run when the XCode project is build.

    Code (CSharp):
    1. PBXProject proj = new PBXProject();
    2. var file = File.ReadAllText(projPath);
    3. proj.ReadFromString(file);
    4.  
    5. string target = proj.GetUnityMainTargetGuid();
    6.  
    7. proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
    8.  
    9. File.WriteAllText(projPath, proj.WriteToString());
    But the setting "ENABLE_BITCODE" is set to "NO" in the targets in Xcode but not on the main Project. So building directly will not work in XCode. Also not in Unity Cloud Build.



    When i change the setting in the project manual then Xcode can build the project.

    Does anyone know what i am doing wrong?
     
  2. ccllz

    ccllz

    Joined:
    Feb 25, 2021
    Posts:
    2
    Use ProjectGuid() replace GetUnityMainTargetGuid()
     
  3. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    44
    This is the code i am using now ... and that is working for me ...


    Code (CSharp):
    1. /// <summary>
    2.     /// This class manages the post build process
    3.     /// </summary>
    4.     public static class BuildPostProcess
    5.     {
    6.         [PostProcessBuildAttribute(999)]
    7.         public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    8.         {
    9.             if (buildTarget != BuildTarget.iOS) return;
    10.  
    11.             // change bitcode to false
    12.             var projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
    13.             Debug.Log("[BuildPostprocess] Build iOS. path: " + projPath);
    14.  
    15.             var proj = new PBXProject();
    16.             var file = File.ReadAllText(projPath);
    17.             proj.ReadFromString(file);
    18.  
    19.             var target = proj.GetUnityMainTargetGuid();
    20.  
    21.             proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
    22.  
    23.             File.WriteAllText(projPath, proj.WriteToString());
    24.  
    25.             Debug.Log("[BuildPostprocess] Bitcode disabled.");
    26.         }
    27.     }
     
unityunity