FileNotFoundException when using Xcode API

We are using the Xcode API to add frameworks, permissions, and update build settings. Currently we use the XcodeAPI code found here, copied into our project:
https://bitbucket.org/Unity-Technologies/xcodeapi

However, seeing as there is a version included in Unity, documented here:

However, I am getting odd build errors when trying to use types in UnityEditor.iOS.Xcode. Here is a minimal sample that reproduces the bugs:

using UnityEngine;
using System.Collections;
using System.IO;

#if UNITY_EDITOR

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public class Editor : MonoBehaviour {
	// A variable from UnityEditor.iOS.Xcode declared in local scope is fine
	public static void LocalScopePlist()
	{
		PlistDocument plist = new PlistDocument();
	}

	// A variable from UnityEditor.iOS.Xcode passed in a function causes an FileNotFoundException
	public static void PassMeAPlist(PlistDocument passedPlist)
	{

	}
}

#endif

Errors I get in the Unity Editor are:

FileNotFoundException: Could not load file or assembly 'UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

FileNotFoundException: Could not load file or assembly 'UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

System.Reflection.MonoMethodInfo.GetMethodInfo (IntPtr handle) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:59)
System.Reflection.MonoMethod.GetPseudoCustomAttributes () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:293)
System.MonoCustomAttrs.GetPseudoCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/MonoCustomAttrs.cs:78)
System.MonoCustomAttrs.IsDefined (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/MonoCustomAttrs.cs:301)
System.Reflection.MonoMethod.IsDefined (System.Type attributeType, Boolean inherit) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:274)
System.Attribute.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType, Boolean inherit) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Attribute.cs:326)
System.Attribute.IsDefined (System.Reflection.MemberInfo element, System.Type attributeType) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Attribute.cs:299)
UnityEditor.EditorAssemblies.ProcessStaticMethodAttributes (System.Type type) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:95)
UnityEditor.EditorAssemblies.ProcessInitializeOnLoadAttributes () (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:130)
UnityEditor.EditorAssemblies.SetLoadedEditorAssemblies (System.Reflection.Assembly assemblies) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:63)

I have confirmed the dll is present at

/Applications/Unity/Unity.app/Contents/PlaybackEngines/iossupport/UnityEditor.iOS.Extensions.Xcode.dll`

Suggestions?

@dustinfreeman Did you ever find a fix for this issue? I just ran into this and I can't seem to find a fix...

2 Answers

2

We just ran in this problem today too. It works for us if we use all UnityEditor.iOS.Xcode related stuff in just one method. The error messages pop up when I move some code in other methods (e.g. a seperate method for setting the build properties).

It works, but I don’t know why. Can someone confirm that?

Yes, I experience the same thing in 5.2.0f3 and in 5.2.1f1 Another way to work around could be to create a non-static class that you can instantiate in you [PostProcessBuildAttribute] decorated method. Refactor you methods that adds frameworks etc. to methods in that class.

Our fix also resembled this. We did everything in a single method, and avoided passing any Xcode API objects around. The case where we noticed this had the above errors appear when we passed a PlistDocument object to a separate function, versus doing the exact same operations in the original function. shrug

That fixes for me too, I have a internal function AddLibToProject(PBXProject inst, string targetGuid, string lib), just remove this function and duplicate the code clear the error... And Unity 5.6.0 claimed to fixed this.

A way to fix just change playeSetting APi CompatibilityLevel to Net2.0 ,then fine.