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.
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).
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Collections;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using System.IO;
using System.Linq;
public class PostBuildProcessor : MonoBehaviour
{
#if UNITY_CLOUD_BUILD
/*
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
- PostBuildProcessor.OnPostprocessBuildiOS
- PostBuildProcessor.OnPostprocessBuildAndroid
depending on the platform they should be executed.
Here is the basic order of operations (e.g. with iOS operation)
- Unity Cloud Build Pre-export methods run
- Export process happens
- Methods marked the built-in PostProcessBuildAttribute are called
- Unity Cloud Build Post-export methods run
- [unity ends]
- (iOS) Xcode processes project
- Done!
More information can be found on http://forum.unity3d.com/threads/solved-ios-build-failed-pushwoosh-dependency.293192/
*/
public static void OnPostprocessBuildiOS (string exportPath)
{
}
#endif
// a normal post process method which is executed by Unity
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
{
#if UNITY_CLOUD_BUILD
Debug.Log("[UCB Demos] OnPostprocessBuildiOS");
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject ();
proj.ReadFromString (File.ReadAllText (projPath));
string target = proj.TargetGuidByName ("Unity-iPhone");
// Set a custom link flag
proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC");
File.WriteAllText (projPath, proj.WriteToString ());
#endif
}
}
Ok I got it to work! Here is the post build script I used, hope this helps anyone else.
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Collections;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using System.IO;
using System.Linq;
public class PostBuildProcessor : MonoBehaviour
{
#if UNITY_IOS
/*
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
- PostBuildProcessor.OnPostprocessBuildiOS
- PostBuildProcessor.OnPostprocessBuildAndroid
depending on the platform they should be executed.
Here is the basic order of operations (e.g. with iOS operation)
- Unity Cloud Build Pre-export methods run
- Export process happens
- Methods marked the built-in PostProcessBuildAttribute are called
- Unity Cloud Build Post-export methods run
- [unity ends]
- (iOS) Xcode processes project
- Done!
More information can be found on http://forum.unity3d.com/threads/solved-ios-build-failed-pushwoosh-dependency.293192/
*/
public static void OnPostprocessBuildiOS (string exportPath)
{
}
#endif
// a normal post process method which is executed by Unity
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
{
#if UNITY_IOS
Debug.Log("OnPostprocessBuildiOS");
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject ();
proj.ReadFromString (File.ReadAllText (projPath));
string target = proj.TargetGuidByName ("Unity-iPhone");
// Set a custom link flag
proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-all_load");
proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC");
// add frameworks
proj.AddFrameworkToProject(target, "AdSupport.framework", true);
proj.AddFrameworkToProject(target, "CoreTelephony.framework", true);
proj.AddFrameworkToProject(target, "EventKit.framework", true);
proj.AddFrameworkToProject(target, "EventKitUI.framework", true);
proj.AddFrameworkToProject(target, "iAd.framework", true);
proj.AddFrameworkToProject(target, "MessageUI.framework", true);
proj.AddFrameworkToProject(target, "StoreKit.framework", true);
proj.AddFrameworkToProject(target, "Security.framework", true);
proj.AddFrameworkToProject(target, "GameKit.framework", true);
File.WriteAllText (projPath, proj.WriteToString ());
#endif
}
}
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?
@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.