Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

[SOLVED] Cloud Build fails when using PostProcessBuild

Discussion in 'Unity Cloud Build' started by bferah, Aug 22, 2020.

  1. bferah

    bferah

    Joined:
    Jul 8, 2017
    Posts:
    7
    When I use cloud build for iOS build with a PostProcessBuild script it won't recognize some of the UnityEditor features, gives some error messages and fails building. Here are the error messages;

    Code (CSharp):
    1.  
    2. 108: [Unity] Assets/Scripts/XCodePostProcess.cs(5,19): error CS0234: The type or namespace name 'Callbacks' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    3. 109: [Unity] Assets/Scripts/XCodePostProcess.cs(6,19): error CS0234: The type or namespace name 'iOS' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    4. 110: [Unity] Assets/Scripts/XCodePostProcess.cs(12,43): error CS0246: The type or namespace name 'BuildTarget' could not be found (are you missing a using directive or an assembly reference?)
    5. 111: [Unity] Assets/Scripts/XCodePostProcess.cs(11,6): error CS0246: The type or namespace name 'PostProcessBuildAttribute' could not be found (are you missing a using directive or an assembly reference?)
    6. 112: [Unity] Assets/Scripts/XCodePostProcess.cs(11,6): error CS0246: The type or namespace name 'PostProcessBuild' could not be found (are you missing a using directive or an assembly reference?)
    7. 113: [Unity] ERROR: Assets/Scripts/XCodePostProcess.cs(5,19): error CS0234: The type or namespace name 'Callbacks' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    8. 114: [Unity] Assets/Scripts/XCodePostProcess.cs(5,19): error CS0234: The type or namespace name 'Callbacks' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    9. 115: [Unity] ERROR: Assets/Scripts/XCodePostProcess.cs(6,19): error CS0234: The type or namespace name 'iOS' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    10. 116: [Unity] Assets/Scripts/XCodePostProcess.cs(6,19): error CS0234: The type or namespace name 'iOS' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    11. 117: [Unity] ERROR: Assets/Scripts/XCodePostProcess.cs(12,43): error CS0246: The type or namespace name 'BuildTarget' could not be found (are you missing a using directive or an assembly reference?)
    12. 118: [Unity] Assets/Scripts/XCodePostProcess.cs(12,43): error CS0246: The type or namespace name 'BuildTarget' could not be found (are you missing a using directive or an assembly reference?)
    13. 119: [Unity] ERROR: Assets/Scripts/XCodePostProcess.cs(11,6): error CS0246: The type or namespace name 'PostProcessBuildAttribute' could not be found (are you missing a using directive or an assembly reference?)
    14. 120: [Unity] Assets/Scripts/XCodePostProcess.cs(11,6): error CS0246: The type or namespace name 'PostProcessBuildAttribute' could not be found (are you missing a using directive or an assembly reference?)
    15. 121: [Unity] ERROR: Assets/Scripts/XCodePostProcess.cs(11,6): error CS0246: The type or namespace name 'PostProcessBuild' could not be found (are you missing a using directive or an assembly reference?)
    16. 122: [Unity] Assets/Scripts/XCodePostProcess.cs(11,6): error CS0246: The type or namespace name 'PostProcessBuild' could not be found (are you missing a using directive or an assembly reference?)
    17.  
    And here is my script;
    Code (CSharp):
    1.  
    2. using System.IO;
    3. using UnityEditor;
    4. using UnityEditor.Callbacks;
    5. using UnityEditor.iOS.Xcode;
    6.  
    7. public class XCodePostProcess
    8. {
    9.     [PostProcessBuild]
    10.     public static void OnPostprocessBuild(BuildTarget target, string path)
    11.     {
    12.         if (target == BuildTarget.iOS)
    13.         {
    14.             string projPath = PBXProject.GetPBXProjectPath(path);
    15.             PBXProject proj = new PBXProject();
    16.  
    17.             proj.ReadFromString(File.ReadAllText(projPath));
    18.             string targetGuid = proj.TargetGuidByName("Unity-iPhone");
    19.  
    20.             proj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
    21.  
    22.             File.WriteAllText(projPath, proj.WriteToString());
    23.         }
    24.     }
    25. }
    26.  
    I need PostProcessBuild because of another build error caused by Facebook SDK I believe. When I build the iOS project with fb sdk imported, it caused some swift framework error that App Store won't accept as it is. I have tried to put this file under the Editor folder but then it didn't worked at all. Any help with that would be really appreciated.
     
    Last edited: Aug 22, 2020
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,001
    Those errors you're getting are because it's not in the Editor folder (it gets compiled into the wrong assembly). I noticed that you said you moved it to the Editor folder and it didn't run but I'm not sure why that would be. It's probably worth adding some Debug.Log commands in and checking your cloud build log to make sure it's even getting to that function.

    p.s. Are you putting the file in Assets\Editor\Build.cs or something similar? Just checking in case you just put it in Editor\Build.cs by accident.
     
    MedwayDDdabrowski likes this.
  3. bferah

    bferah

    Joined:
    Jul 8, 2017
    Posts:
    7
    Firstly thanks for your suggestion @tonemcbride . The actual solution for my problem was a mixture of something that I found on stackoverflow and putting the csharp file back in the editor folder. Anyone who is having a similar problem with having their game uploaded to App Store because of the swift framework library error, the final solution is like this;
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Callbacks;
    3. using UnityEditor.iOS.Xcode;
    4.  
    5. public class XCodePostProcess
    6. {
    7.     [PostProcessBuild]
    8.     public static void OnPostprocessBuild(BuildTarget target, string path)
    9.     {
    10.         if (target == BuildTarget.iOS)
    11.         {
    12.             string projPath = PBXProject.GetPBXProjectPath(path);
    13.             PBXProject proj = new PBXProject();
    14.             proj.ReadFromFile(projPath);
    15.  
    16.             string targetGuid = proj.GetUnityMainTargetGuid();
    17.  
    18.             foreach (var framework in new[] { targetGuid, proj.GetUnityFrameworkTargetGuid() })
    19.             {
    20.                 proj.SetBuildProperty(framework, "ENABLE_BITCODE", "NO");
    21.                 proj.SetBuildProperty(framework, "EMBEDDED_CONTENT_CONTAINS_SWIFT", "YES");
    22.                 proj.SetBuildProperty(framework, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
    23.                 proj.SetBuildProperty(framework, "SWIFT_VERSION", "5.0");
    24.             }
    25.  
    26.             proj.WriteToFile(projPath);
    27.         }
    28.     }
    29. }
     
  4. PorpoiseStudios

    PorpoiseStudios

    Joined:
    Oct 12, 2019
    Posts:
    6
    Thank you for this solution! I was running into this error:

    1303: ▸ ❌; error: Value for SWIFT_VERSION cannot be empty. (in target 'UnityFramework' from project

    And your snippet above did the trick. I only needed to set the SWIFT_VERSION line and everything else worked.
     
  5. Qhuhuit

    Qhuhuit

    Joined:
    Feb 17, 2018
    Posts:
    20
    Exactly what I was looking for ! Thank you so much. So how do you set up this script in cloud build ? I'm new to this area..
     
  6. gaps

    gaps

    Joined:
    Jan 1, 2014
    Posts:
    8
    Code (CSharp):
    1. #if UNITY_EDITOR && UNITY_IOS
    2. using UnityEditor;
    3. using UnityEditor.Callbacks;
    4. using UnityEditor.iOS.Xcode;
    5.  
    6. public class BuildPostProcessor
    7. {
    8.     [PostProcessBuild]
    9.     public static void OnPostProcessBuild(BuildTarget target, string path)
    10.     {
    11.         if (target == BuildTarget.iOS)
    12.         {
    13.             string projPath = PBXProject.GetPBXProjectPath(path);
    14.  
    15.             PBXProject proj = new PBXProject();
    16.             proj.ReadFromFile(projPath);
    17.  
    18.             string targetGUID = proj.GetUnityFrameworkTargetGuid();
    19.             proj.AddBuildProperty(targetGUID, "SWIFT_VERSION", "5.1");
    20.  
    21.             proj.WriteToFile(projPath);
    22.         }
    23.     }
    24. }
    25. #endif
    26.  
    This is everything needed to solve the issue, put it in a C# script anywhere in the project.
     
    wenlu_unity and Qhuhuit like this.
unityunity