Unity export XCode project running error:'UnityFramework/UnityFramework.h' file not found

Introduction

Recently, the project was upgraded to version 2019.4.10f1. When using automated packaging, I encountered some problems. One of them was that after exporting the XCode project, when running the project, the compilation error: 'UnityFramework/UnityFramework.h' file not found


There was no problem in the previous version. At this time, look at the project structure. The XCode directory exported by Unity is different from the previous version. There is now a MainApp folder with the entry file main.mm.
Click to open main.mm and see the error line, header The file reference include <UnityFramework/UnityFramework.h>, look at the UnityFramework folder and UnityFramework.h header file in the project directory, but the hierarchy of the folder is wrong

So you only need to add processing in the automated packaging code and change the reference to the correct path.

public static void OnPostProcessBuild( BuildTarget target, string pathToBuiltProject )
	{
        if (target != BuildTarget.iOS) 
		{
			Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
			return;
		}
		
		//main.mm中找不到UnityFramework/UnityFramework.h的问题
		var mainAppPath = Path.Combine(pathToBuiltProject, "MainApp", "main.mm");
		var mainContent = File.ReadAllText(mainAppPath);
		var newContent = mainContent.Replace("#include <UnityFramework/UnityFramework.h>", @"#include ""../UnityFramework/UnityFramework.h""");
		File.WriteAllText(mainAppPath, newContent);
	}

Package again, open main.mm and the reference has been modified

Compile pass

Guess you like

Origin blog.csdn.net/mango9126/article/details/114835717