diff --git a/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs b/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs index b82c1ca..86d5673 100644 --- a/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs +++ b/Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs @@ -37,15 +37,25 @@ namespace HybridCLR.Editor.BuildProcessors { string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8); string removeBuildOption = @"--external-lib-il2-cpp=\""$PROJECT_DIR/Libraries/libil2cpp.a\"""; - if (!pbxprojContent.Contains(removeBuildOption)) + if (pbxprojContent.Contains(removeBuildOption)) { - //throw new BuildFailedException("modified project.pbxproj fail"); - Debug.LogError("[AddLil2cppSourceCodeToXcodeproj] modified project.pbxproj fail"); - return; + pbxprojContent = pbxprojContent.Replace(removeBuildOption, ""); + Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'"); } - pbxprojContent = pbxprojContent.Replace(removeBuildOption, ""); + else + { + Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] project.pbxproj remove building option:'{removeBuildOption}' fail. This may occur when 'Append' to existing xcode project in building"); + } + + int strShellScriptIndex1 = pbxprojContent.IndexOf("/* ShellScript */,"); + int strShellScriptIndex2 = pbxprojContent.IndexOf("/* ShellScript */,", strShellScriptIndex1 + 10); + if (strShellScriptIndex2 >= 0) + { + pbxprojContent = pbxprojContent.Remove(strShellScriptIndex1, strShellScriptIndex2 - strShellScriptIndex1); + Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] remove duplicated '/* ShellScript */' from file '{pbxprojFile}'"); + } + File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8); - Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'"); } private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject)