Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

iOS build errors from missing libraries

Discussion in 'Unity Cloud Build' started by dustinandrew, Apr 13, 2015.

  1. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    93
    I'm building for iOS on Unity Cloud and my game uses the Reign Ultimate Unified API plugin. It's getting build errors when building the xcode project. The plugin's developer says I need to add compile link options "-all_load" and "-ObjC" in the xcode project to include all the iOS libraries.

    How do I do this when building with Unity Cloud?

    I'm guessing I will just have to not use Unity Cloud for now until they add more features for customizing the xcode settings. :(
     
  2. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    93
    Here is the Cloud error log:

    And here is the xcode error when just building directly from unity:
     
  3. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    678
    You need to use the XCode manipulation API to update the XCode project in a post process build step, it's pretty easy. Check out the Native Library Demo in UCB Demos on how to achieve it. In theory you just need a PostBuildProcessor.cs file in an Editor folder with following content (I just made it without compiler so it might not compile straight away but the UCB Demo does).

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.Callbacks;
    4. using System.Collections;
    5. #if UNITY_IOS
    6. using UnityEditor.iOS.Xcode;
    7. #endif
    8. using System.IO;
    9. using System.Linq;
    10.  
    11. public class PostBuildProcessor : MonoBehaviour
    12. {
    13.     #if UNITY_CLOUD_BUILD
    14.     /*
    15.     This methods are per platform post export methods. They can be added additionally to the post process attributes in the Advanced Features Settings on UCB using
    16.     - PostBuildProcessor.OnPostprocessBuildiOS
    17.     - PostBuildProcessor.OnPostprocessBuildAndroid
    18.     depending on the platform they should be executed.
    19.  
    20.     Here is the basic order of operations (e.g. with iOS operation)
    21.     - Unity Cloud Build Pre-export methods run
    22.     - Export process happens
    23.     - Methods marked the built-in PostProcessBuildAttribute are called
    24.     - Unity Cloud Build Post-export methods run
    25.     - [unity ends]
    26.     - (iOS) Xcode processes project
    27.     - Done!
    28.     More information can be found on http://forum.unity3d.com/threads/solved-ios-build-failed-pushwoosh-dependency.293192/
    29.     */
    30.     public static void OnPostprocessBuildiOS (string exportPath)
    31.     {
    32.     }
    33.     #endif
    34.  
    35.     // a normal post process method which is executed by Unity
    36.     [PostProcessBuild]
    37.     public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
    38.     {
    39.         #if UNITY_CLOUD_BUILD
    40.  
    41.             Debug.Log("[UCB Demos] OnPostprocessBuildiOS");
    42.             string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    43.              
    44.             PBXProject proj = new PBXProject ();
    45.             proj.ReadFromString (File.ReadAllText (projPath));
    46.          
    47.             string target = proj.TargetGuidByName ("Unity-iPhone");
    48.                      
    49.             // Set a custom link flag
    50.             proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC");
    51.          
    52.             File.WriteAllText (projPath, proj.WriteToString ());
    53.  
    54.         #endif
    55.     }
    56. }
    57.  
     
  4. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    93
    Thanks David! I did this, but also adding the all load flag:
    Code (CSharp):
    1. proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-all_load");
    And still get errors, I'm going to talk to the plugin dev, I think the problem is with it and not with unity cloud.

    Here is from the full cloud log where the error occurs:
     
    Last edited: Apr 13, 2015
  5. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    93
    Ok I got it to work! Here is the post build script I used, hope this helps anyone else.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.Callbacks;
    4. using System.Collections;
    5. #if UNITY_IOS
    6. using UnityEditor.iOS.Xcode;
    7. #endif
    8. using System.IO;
    9. using System.Linq;
    10.  
    11. public class PostBuildProcessor : MonoBehaviour
    12. {
    13.     #if UNITY_IOS
    14.     /*
    15.     This methods are per platform post export methods. They can be added additionally to the post process attributes in the Advanced Features Settings on UCB using
    16.     - PostBuildProcessor.OnPostprocessBuildiOS
    17.     - PostBuildProcessor.OnPostprocessBuildAndroid
    18.     depending on the platform they should be executed.
    19.     Here is the basic order of operations (e.g. with iOS operation)
    20.     - Unity Cloud Build Pre-export methods run
    21.     - Export process happens
    22.     - Methods marked the built-in PostProcessBuildAttribute are called
    23.     - Unity Cloud Build Post-export methods run
    24.     - [unity ends]
    25.     - (iOS) Xcode processes project
    26.     - Done!
    27.     More information can be found on http://forum.unity3d.com/threads/solved-ios-build-failed-pushwoosh-dependency.293192/
    28.     */
    29.     public static void OnPostprocessBuildiOS (string exportPath)
    30.     {
    31.     }
    32.     #endif
    33.    
    34.     // a normal post process method which is executed by Unity
    35.     [PostProcessBuild]
    36.     public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
    37.     {
    38.         #if UNITY_IOS
    39.        
    40.         Debug.Log("OnPostprocessBuildiOS");
    41.         string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    42.        
    43.         PBXProject proj = new PBXProject ();
    44.         proj.ReadFromString (File.ReadAllText (projPath));
    45.        
    46.         string target = proj.TargetGuidByName ("Unity-iPhone");
    47.        
    48.         // Set a custom link flag
    49.         proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-all_load");
    50.         proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC");
    51.  
    52.         // add frameworks
    53.         proj.AddFrameworkToProject(target, "AdSupport.framework", true);
    54.         proj.AddFrameworkToProject(target, "CoreTelephony.framework", true);
    55.         proj.AddFrameworkToProject(target, "EventKit.framework", true);
    56.         proj.AddFrameworkToProject(target, "EventKitUI.framework", true);
    57.         proj.AddFrameworkToProject(target, "iAd.framework", true);
    58.         proj.AddFrameworkToProject(target, "MessageUI.framework", true);
    59.         proj.AddFrameworkToProject(target, "StoreKit.framework", true);
    60.         proj.AddFrameworkToProject(target, "Security.framework", true);
    61.         proj.AddFrameworkToProject(target, "GameKit.framework", true);
    62.        
    63.         File.WriteAllText (projPath, proj.WriteToString ());
    64.        
    65.         #endif
    66.     }
    67. }
     
    SanSolo and David-Berger like this.
  6. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    678
    Brilliant! Thanks for sharing! :)
     
  7. Colgruv

    Colgruv

    Joined:
    Jan 15, 2015
    Posts:
    6
    One issue people seem to have had with XCode and Unity5 is with Automatic Reference Counting, resulting in errors like:
    • error: 'retain' is unavailable: not available in automatic reference counting mode
    • error: ARC forbids explicit message send of 'retain'
    • error: 'release' is unavailable: not available in automatic reference counting mode
    • error: ARC forbids explicit message send of 'release'
    I'm attempting to use the post process build processes to resolve this, but with little success. I'm not super experienced with iOS development but it seems like normally there is a way to turn ARC off using Build Settings, but I'm not sure how I'd accomplish this using a post build script?
     

    Attached Files:

  8. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    678
    Does this work locally? Seems like this is related to some plugins you use, can you tell me which ones those are?
     
  9. psykojello2

    psykojello2

    Joined:
    Jul 19, 2013
    Posts:
    37
    @David Berger , do you have a reference for which flags correspond to what settings? Is there a way I can figure it out myself?

    i.e. how do you know that "OTHER_LDFLAGS" is the right place to add -ObjC ?

    In particular I want to know how to enable Push Notification in my XCode project. Thanks!
     
  10. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    678
    @psykojello2 This is something you find out when you natively integrate something with Objectiv C and you need to add it to XCode in the end, sometimes mentioned in the Apple documentation or compiler documentation.
     
unityunity