コード例 #1
29
ファイル: FiksuPostBuild.cs プロジェクト: zrrz/GrooveGame
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        #if UNITY_IPHONE
        string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

        PBXProject project = new PBXProject();

        project.ReadFromString(File.ReadAllText(projectPath));

        // This is the project name that Unity generates for iOS, isn't editable until after post processing
        string target = project.TargetGuidByName(PBXProject.GetUnityTargetName());

        #if UNITY_5_0
        project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks/Plugins/iOS");
        #else
        CopyAndReplaceDirectory("Assets/Plugins/iOS/FiksuSDK.bundle", Path.Combine(path, "Frameworks/FiksuSDK.bundle"));
        project.AddFileToBuild(target, project.AddFile("Frameworks/FiksuSDK.bundle", "Frameworks/FiksuSDK.bundle", PBXSourceTree.Source));

        CopyAndReplaceDirectory("Assets/Plugins/iOS/FiksuSDK.framework", Path.Combine(path, "Frameworks/FiksuSDK.framework"));
        project.AddFileToBuild(target, project.AddFile("Frameworks/FiksuSDK.framework", "Frameworks/FiksuSDK.framework", PBXSourceTree.Source));

        project.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
        project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");
        #endif

        project.AddFrameworkToProject(target, "AdSupport.framework", true);
        project.AddFrameworkToProject(target, "StoreKit.framework", true);
        project.AddFrameworkToProject(target, "Security.framework", true);
        project.AddFrameworkToProject(target, "SystemConfiguration.framework", false);
        project.AddFrameworkToProject(target, "MessageUI.framework", false);

        File.WriteAllText(projectPath, project.WriteToString());
        #endif
    }
コード例 #2
0
    // 设置Xcode配置
    public static void ModifyProj(string path)
    {
        string     projPath = PBXProject.GetPBXProjectPath(path);
        PBXProject pbxProj  = new PBXProject();

        pbxProj.ReadFromString(File.ReadAllText(projPath));

        // 配置目标TARGETS
        string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");

        // 关闭bitcode
        //pbxProj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "false");

        // 添加头文件搜索路径
        pbxProj.AddBuildProperty(targetGuid, "HEADER_SEARCH_PATHS", "$(SRCROOT)/Libraries/Plugins/iOS");

        // 添加.tbd
        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));

        // 设置TeamID
        //...

        File.WriteAllText(projPath, pbxProj.WriteToString());
    }
コード例 #3
0
        public void updateProject(BuildTarget buildTarget, string projectPath)
        {
            Debug.Log("IronSource - Update project for Tapjoy");

            PBXProject project = new PBXProject();

            project.ReadFromString(File.ReadAllText(projectPath));

            string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());

            // Required System Frameworks
            project.AddFrameworkToProject(targetId, "CoreData.framework", false);
            project.AddFrameworkToProject(targetId, "CoreMotion.framework", false);
            project.AddFrameworkToProject(targetId, "MapKit.framework", false);
            project.AddFrameworkToProject(targetId, "MediaPlayer.framework", false);
            project.AddFrameworkToProject(targetId, "MessageUI.framework", false);              //Not required for SDK 11.9 and higher
            project.AddFrameworkToProject(targetId, "UIKit.framework", false);

            project.AddFileToBuild(targetId, project.AddFile("usr/lib/libsqlite3.0.tbd", "Frameworks/libsqlite3.0.tbd", PBXSourceTree.Sdk));
            project.AddFileToBuild(targetId, project.AddFile("usr/lib/libxml2.tbd", "Frameworks/libxml2.tbd", PBXSourceTree.Sdk));
            project.AddFileToBuild(targetId, project.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
            project.AddFileToBuild(targetId, project.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));

            // Optional Frameworks
            project.AddFrameworkToProject(targetId, "PassKit.framework", true);
            project.AddFrameworkToProject(targetId, "Social.framework", true);

            File.WriteAllText(projectPath, project.WriteToString());
        }
コード例 #4
0
        private static void EditXcodeProject(string buildFolder)
        {
            PBXProject project = new PBXProject();
            string     path    = Path.Combine(buildFolder, FileUtil.NiceWinPath("Unity-iPhone.xcodeproj/project.pbxproj"));

            project.ReadFromFile(path);
            string targetGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName());

            if (AdvertisementSettings.enabled && AdvertisementSettings.IsPlatformEnabled(RuntimePlatform.IPhonePlayer))
            {
                string target = Path.Combine(buildFolder, Path.Combine("UnityAds", "UnityAds.framework"));
                FileUtil.CopyDirectoryRecursive(Path.Combine(extensionPath, FileUtil.NiceWinPath("Editor/Resources/iOS/builds/UnityAds.framework")), target, true);
                project.AddFileToBuild(targetGuid, project.AddFile(Path.Combine("UnityAds", "UnityAds.framework"), "Frameworks/UnityAds.framework", PBXSourceTree.Source));
                project.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(SRCROOT)/UnityAds");
                project.AddFrameworkToProject(targetGuid, "AdSupport.framework", true);
                project.AddFrameworkToProject(targetGuid, "StoreKit.framework", false);
                project.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
            }
            else
            {
                project.RemoveFile(project.FindFileGuidByRealPath(Path.Combine("UnityAds", "UnityAds.framework")));
                string[] removeValues = new string[] { "$(SRCROOT)/UnityAds" };
                project.UpdateBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", null, removeValues);
                string str5 = Path.Combine(buildFolder, "UnityAds");
                if (Directory.Exists(str5))
                {
                    Directory.Delete(str5, true);
                }
            }
            project.AddFileToBuild(targetGuid, project.AddFile("UnityAdsConfig.h", "Classes/UnityAds/UnityAdsConfig.h"));
            project.WriteToFile(path);
        }
コード例 #5
0
        /// <summary>
        /// Get existing entitlements file if exists or creates a new file, adds it to the project, and returns the path
        /// </summary>
        private string GetEntitlementsPath(string targetGuid, string targetName)
        {
            var relativePath = _project.GetBuildPropertyForAnyConfig(targetGuid, "CODE_SIGN_ENTITLEMENTS");

            if (relativePath != null)
            {
                var fullPath = Path.Combine(_outputPath, relativePath);

                if (File.Exists(fullPath))
                {
                    return(fullPath);
                }
            }

            var entitlementsPath = Path.Combine(_outputPath, targetName, $"{targetName}.entitlements");

            // make new file
            var entitlementsPlist = new PlistDocument();

            entitlementsPlist.WriteToFile(entitlementsPath);

            // Copy the entitlement file to the xcode project
            var entitlementFileName = Path.GetFileName(entitlementsPath);
            var relativeDestination = targetName + "/" + entitlementFileName;

            // Add the pbx configs to include the entitlements files on the project
            _project.AddFile(relativeDestination, entitlementFileName);
            _project.SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeDestination);

            return(relativeDestination);
        }
コード例 #6
0
        static void ConfigureXcodeForCarthage()
        {
            var path    = PBXProject.GetPBXProjectPath(projectRoot);
            var project = new PBXProject();

            project.ReadFromFile(path);
#if UNITY_2019_3_OR_NEWER
            var target = project.GetUnityFrameworkTargetGuid();
#else
            var target = project.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif

            project.AddFileToBuild(
                target,
                project.AddFile("Carthage/Build/iOS/LineSDK.framework", "Frameworks/LineSDK.framework",
                                PBXSourceTree.Source));
            project.AddFileToBuild(
                target,
                project.AddFile("Carthage/Build/iOS/LineSDKObjC.framework", "Frameworks/LineSDKObjC.framework.framework",
                                PBXSourceTree.Source));

            project.SetBuildProperty(target, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
            project.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
            project.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Carthage/Build/iOS");

            project.WriteToFile(path);
        }
コード例 #7
0
        private static void AddGetSocialCoreFramework(ref PBXProject project, string target)
        {
            project.AddFileToBuild(target, project.AddFile("Frameworks/GetSocial.embeddedframework/GetSocial.framework", "Frameworks/GetSocial.embeddedframework/GetSocial.framework", PBXSourceTree.Source));
            project.AddFileToBuild(target, project.AddFile("Frameworks/GetSocial.embeddedframework/Resources/GetSocial.bundle", "Frameworks/GetSocial.embeddedframework/Resources/GetSocial.bundle", PBXSourceTree.Source));

            // add framework directory to the framework include path
            // project.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks/GetSocial.embeddedframework");

            // add dependencies
            project.AddDynamicLibraryToProject(target, "libsqlite3.dylib");
            project.AddFrameworkToProject(target, "Accelerate.framework", weak: false);
            project.AddFrameworkToProject(target, "AdSupport.framework", weak: false);
            project.AddFrameworkToProject(target, "AVFoundation.framework", weak: false);
            project.AddFrameworkToProject(target, "CFNetwork.framework", weak: false);
            project.AddFrameworkToProject(target, "CoreFoundation.framework", weak: false);
            project.AddFrameworkToProject(target, "CoreGraphics.framework", weak: false);
            project.AddFrameworkToProject(target, "CoreImage.framework", weak: false);
            project.AddFrameworkToProject(target, "CoreTelephony.framework", weak: false);
            project.AddFrameworkToProject(target, "CoreText.framework", weak: false);
            project.AddFrameworkToProject(target, "Foundation.framework", weak: false);
            project.AddFrameworkToProject(target, "MessageUI.framework", weak: false);
            project.AddFrameworkToProject(target, "MobileCoreServices.framework", weak: false);
            project.AddFrameworkToProject(target, "QuartzCore.framework", weak: false);
            project.AddFrameworkToProject(target, "Security.framework", weak: false);
            project.AddFrameworkToProject(target, "Social.framework", weak: false);
            project.AddFrameworkToProject(target, "SystemConfiguration.framework", weak: false);
            project.AddFrameworkToProject(target, "UIKit.framework", weak: false);
        }
コード例 #8
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();

            proj.ReadFromString(File.ReadAllText(projPath));
            string target = proj.TargetGuidByName("Unity-iPhone");

            // システムのフレームワークを追加
            proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false);

            // 自前のフレームワークを追加
            CopyAndReplaceDirectory("Assets/Lib/mylib.framework", Path.Combine(path, "Frameworks/mylib.framework"));
            proj.AddFileToBuild(target, proj.AddFile("Frameworks/mylib.framework", "Frameworks/mylib.framework", PBXSourceTree.Source));

            // ファイルを追加
            var fileName = "my_file.xml";
            var filePath = Path.Combine("Assets/Lib", fileName);
            File.Copy(filePath, Path.Combine(path, fileName));
            proj.AddFileToBuild(target, proj.AddFile(fileName, fileName, PBXSourceTree.Source));

            // Yosemiteでipaが書き出せないエラーに対応するための設定
            proj.SetBuildProperty(target, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");

            // フレームワークの検索パスを設定・追加
            proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // 書き出し
            File.WriteAllText(projPath, proj.WriteToString());
        }
    }
コード例 #9
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iPhone)
        {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));

            string target = proj.TargetGuidByName("Unity-iPhone");

            // Add user packages to project. Most other source or resource files and packages
            // can be added the same way.
            CopyAndReplaceDirectory("NativeAssets/TestLib.bundle", Path.Combine(path, "Frameworks/TestLib.bundle"));
            proj.AddFileToBuild(target, proj.AddFile("Frameworks/TestLib.bundle",
                                                     "Frameworks/TestLib.bundle", PBXSourceTree.Source));

            CopyAndReplaceDirectory("NativeAssets/TestLib.framework", Path.Combine(path, "Frameworks/TestLib.framework"));
            proj.AddFileToBuild(target, proj.AddFile("Frameworks/TestLib.framework",
                                                     "Frameworks/TestLib.framework", PBXSourceTree.Source));

            // Add custom system frameworks. Duplicate frameworks are ignored.
            // needed by our native plugin in Assets/Plugins/iOS
            proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false /*not weak*/);

            // Add our framework directory to the framework include path
            proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // Set a custom link flag
            proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");

            File.WriteAllText(projPath, proj.WriteToString());
        }
    }
コード例 #10
0
        public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
        {
                        #if UNITY_4_6
            if (buildTarget == BuildTarget.iPhone)
                        #else
            if (buildTarget == BuildTarget.iOS)
                        #endif
            {
                string projPath = PBXProject.GetPBXProjectPath(path);

                // Fix on 4.6.x
                                #if UNITY_4_6
                if (!projPath.Contains("Unity-iPhone.xcodeproj"))
                {
                    projPath = projPath.Replace("Unity-iPhone", "Unity-iPhone.xcodeproj");
                }
                                #endif

                PBXProject proj = new PBXProject();
                proj.ReadFromString(File.ReadAllText(projPath));

                string targetName = PBXProject.GetUnityTargetName();
                string target     = proj.TargetGuidByName(targetName);

                proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", PBXSourceTree.Sdk));
                proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", PBXSourceTree.Sdk));
                proj.AddFileToBuild(target, proj.AddFile("Frameworks/AdSupport.framework", "Frameworks/AdSupport.framework", PBXSourceTree.Sdk));

                File.WriteAllText(projPath, proj.WriteToString());
            }
        }
コード例 #11
0
        private static void AddAdaptersDirectory(string path, PBXProject proj, string targetGuid)
        {
            if (path.EndsWith("__MACOSX", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            if (path.EndsWith(".framework", StringComparison.CurrentCultureIgnoreCase))
            {
                proj.AddFileToBuild(targetGuid, proj.AddFile(path, path));
                var tmp = Utils.FixSlashesInPath(
                    $"$(PROJECT_DIR)/{path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar))}");
                proj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", tmp);
                return;
            }

            if (path.EndsWith(".bundle", StringComparison.CurrentCultureIgnoreCase))
            {
                proj.AddFileToBuild(targetGuid, proj.AddFile(path, path));
                return;
            }

            string fileName;
            var    libPathAdded  = false;
            var    headPathAdded = false;

            var realDstPath = Path.Combine(absoluteProjPath, path);

            foreach (var filePath in Directory.GetFiles(realDstPath))
            {
                fileName = Path.GetFileName(filePath);

                if (fileName.EndsWith(".DS_Store", StringComparison.Ordinal))
                {
                    continue;
                }

                proj.AddFileToBuild(targetGuid,
                                    proj.AddFile(Path.Combine(path, fileName), Path.Combine(path, fileName)));
                if (!libPathAdded && fileName.EndsWith(".a", StringComparison.Ordinal))
                {
                    proj.AddBuildProperty(targetGuid, "LIBRARY_SEARCH_PATHS",
                                          Utils.FixSlashesInPath($"$(PROJECT_DIR)/{path}"));
                    libPathAdded = true;
                }

                if (headPathAdded || !fileName.EndsWith(".h", StringComparison.Ordinal))
                {
                    continue;
                }
                proj.AddBuildProperty(targetGuid, "HEADER_SEARCH_PATHS",
                                      Utils.FixSlashesInPath($"$(PROJECT_DIR)/{path}"));
                headPathAdded = true;
            }

            foreach (var subPath in Directory.GetDirectories(realDstPath))
            {
                AddAdaptersDirectory(Path.Combine(path, Path.GetFileName(subPath)), proj, targetGuid);
            }
        }
コード例 #12
0
    public static void ModifyProj(string path)
    {
        string     projPath = PBXProject.GetPBXProjectPath(path);
        PBXProject pbxProj  = new PBXProject();

        // 配置目标
        pbxProj.ReadFromString(File.ReadAllText(projPath));
        string targetGuid = pbxProj.TargetGuidByName("Unity-iPhone");

        // 添加内置框架
        pbxProj.AddFrameworkToProject(targetGuid, "Security.framework", false);         //weak: true:optional, false:required
        pbxProj.AddFrameworkToProject(targetGuid, "CoreLocation.framework", false);
        pbxProj.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
        pbxProj.AddFrameworkToProject(targetGuid, "GLKit.framework", false);
        pbxProj.AddFrameworksBuildPhase(targetGuid);

        // 添加.tbd
        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
        pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));

        // 设置teamID
        //...

        File.WriteAllText(projPath, pbxProj.WriteToString());
    }
コード例 #13
0
        static void PostProcessBuild(BuildTarget target, string pathToBuildProject)
        {
            if (target == BuildTarget.iOS)
            {
#if UNITY_IOS
                //Xcode
                Debug.Log("PostProcessBuild Bugly Xcode");
                string projPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
                if (!File.Exists(projPath))
                {
                    Debug.LogError("path not exists: " + projPath);
                    return;
                }
                PBXProject pbxProj = new PBXProject();
                pbxProj.ReadFromFile(projPath);
                string targetGuid = pbxProj.TargetGuidByName(PBXProject.GetUnityTargetName());

                //在 libBuglyBridge.a 上设置 framework
                //default
                //pbxProj.AddFrameworkToProject(targetGuid, "Security.framework", false);
                //pbxProj.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", false);
                //pbxProj.AddFrameworkToProject(targetGuid, "JavaScriptCore.framework", true);

                pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
                pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));

                pbxProj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
                //pbxProj.SetBuildProperty(targetGuid, "DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym");
                //pbxProj.SetBuildProperty(targetGuid, "GENERATE_DEBUG_SYMBOLS", "yes");
                pbxProj.WriteToFile(projPath);
#endif
            }
        }
コード例 #14
0
    public static void LinkLibraries(string path)
    {
        string     projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

        proj.ReadFromFile(projPath);
        string target = GetTargetGuid(proj);


        // embedded frameworks
#if UNITY_2019_1_OR_NEWER
        target = proj.GetUnityMainTargetGuid();
#endif
        const string defaultLocationInProj        = "AgoraEngine/Plugins/iOS";
        const string AgoraRtcKitFrameworkName     = "AgoraRtcKit.framework";
        const string AgorafdkaacFrameworkName     = "Agorafdkaac.framework";
        const string AgoraSoundTouchFrameworkName = "AgoraSoundTouch.framework";

        string AgoraRtcKitFrameworkPath     = Path.Combine(defaultLocationInProj, AgoraRtcKitFrameworkName);
        string AgorafdkaacFrameworkPath     = Path.Combine(defaultLocationInProj, AgorafdkaacFrameworkName);
        string AgoraSoundTouchFrameworkPath = Path.Combine(defaultLocationInProj, AgoraSoundTouchFrameworkName);

        string fileGuid = proj.AddFile(AgoraRtcKitFrameworkPath, "Frameworks/" + AgoraRtcKitFrameworkPath, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
        fileGuid = proj.AddFile(AgorafdkaacFrameworkPath, "Frameworks/" + AgorafdkaacFrameworkPath, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
        fileGuid = proj.AddFile(AgoraSoundTouchFrameworkPath, "Frameworks/" + AgoraSoundTouchFrameworkPath, PBXSourceTree.Sdk);
        PBXProjectExtensions.AddFileToEmbedFrameworks(proj, target, fileGuid);
        proj.SetBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");

        // done, write to the project file
        File.WriteAllText(projPath, proj.WriteToString());
    }
コード例 #15
0
        public void AddMultipleSourceFilesWorks()
        {
            ResetGuidGenerator();
            PBXProject proj   = ReadPBXProject();
            string     target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

            // check addition of relative path
            proj.AddFileToBuild(target, proj.AddFile("relative/path1.cc", "Classes/some/path/path1.cc", PBXSourceTree.Source));
            // check addition of absolute path
            proj.AddFileToBuild(target, proj.AddFile("/absolute/path/abs1.cc", "Classes/some/path/abs1.cc", PBXSourceTree.Source));
            proj.AddFileToBuild(target, proj.AddFile("/absolute/path/abs2.cc", "Classes/some/abs2.cc", PBXSourceTree.Source));
            // check addition of files with unknown extensions
            proj.AddFileToBuild(target, proj.AddFile("relative/path1.unknown_ext", "Classes/some/path/path1.unknown_ext", PBXSourceTree.Source));
            // check whether folder references work
            proj.AddFileToBuild(target, proj.AddFolderReference("relative/path2", "Classes/some/path/path2", PBXSourceTree.Source));
            // check whether we correctly add folder references with weird extensions to resources
            proj.AddFileToBuild(target, proj.AddFolderReference("relative/path3.cc", "Classes/some/path/path3.cc", PBXSourceTree.Source));
            // check whether we correctly add files which are not buildable
            proj.AddFileToBuild(target, proj.AddFolderReference("relative/lib.dll", "Classes/some/path/lib.dll", PBXSourceTree.Source));

            Assert.IsTrue(proj.FindFileGuidByRealPath("relative/path1.cc") == "CCCCCCCC0000000000000001");
            Assert.IsTrue(proj.FindFileGuidByRealPath("/absolute/path/abs1.cc") == "CCCCCCCC0000000000000005");
            Assert.IsTrue(proj.FindFileGuidByProjectPath("Classes/some/path/abs1.cc") == "CCCCCCCC0000000000000005");
            Assert.AreEqual(1, proj.GetGroupChildrenFiles("Classes/some").Count);

            TestOutput(proj, "add_file2.pbxproj");
        }
コード例 #16
0
    internal static void CopyAndReplaceDirectory(string srcPath, string dstPath)
    {
        if (Directory.Exists(dstPath))
        {
            Directory.Delete(dstPath);
        }
        if (File.Exists(dstPath))
        {
            File.Delete(dstPath);
        }

        Directory.CreateDirectory(dstPath);

        foreach (var file in Directory.GetFiles(srcPath))
        {
            File.Copy(file, Path.Combine(dstPath, Path.GetFileName(file)));

            //ignore useless files for 'Copy Bundle Resources'
            if (!file.Contains(".DS_Store") && !file.Contains(".framework"))
            {
                proj.AddFileToBuild(targetGuid, proj.AddFile(Path.Combine(dstPath, Path.GetFileName(file)), Path.Combine(dstPath, Path.GetFileName(file)), PBXSourceTree.Source));
            }
        }

        foreach (var dir in Directory.GetDirectories(srcPath))
        {
            CopyAndReplaceDirectory(dir, Path.Combine(dstPath, Path.GetFileName(dir)));
            if (Path.GetFileName(dir).Contains(".bundle"))
            {
                proj.AddFolderReference(Path.Combine(dstPath, Path.GetFileName(dir)), Path.Combine(dstPath, Path.GetFileName(dir)), PBXSourceTree.Source);
                proj.AddFileToBuild(targetGuid, proj.AddFile(Path.Combine(dstPath, Path.GetFileName(dir)), Path.Combine(dstPath, Path.GetFileName(dir)), PBXSourceTree.Source));
            }
        }
    }
コード例 #17
0
    public static void ModifyProj(string pathToBuildProject)
    {
        string     _projPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
        PBXProject _pbxProj  = new PBXProject();

        _pbxProj.ReadFromString(File.ReadAllText(_projPath));

        //获取当前项目名字
        string _targetGuid = _pbxProj.TargetGuidByName("Unity-iPhone");//PBXProject.GetUnityTargetName()

        //*******************************添加framework*******************************//
        _pbxProj.AddFrameworkToProject(_targetGuid, "StoreKit.framework", true);
        _pbxProj.AddFrameworkToProject(_targetGuid, "Security.framework", false);
        _pbxProj.AddFrameworkToProject(_targetGuid, "JavaScriptCore.framework", false);
        _pbxProj.AddFrameworkToProject(_targetGuid, "libc++.1.tbd", false);
        _pbxProj.AddFrameworkToProject(_targetGuid, "libz.1.tbd", false);


        //*******************************添加tbd*******************************//
        _pbxProj.AddFileToBuild(_targetGuid, _pbxProj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
        _pbxProj.AddFileToBuild(_targetGuid, _pbxProj.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));

        #region 第三方的
        //------
        //文件夹下所有文件
        CopyAndReplaceDirectory("Assets/Lib/mylib.framework", Path.Combine(pathToBuildProject, "Frameworks/mylib.framework"));
        _pbxProj.AddFileToBuild(_targetGuid, _pbxProj.AddFile("Frameworks/mylib.framework", "Frameworks/mylib.framework", PBXSourceTree.Source));

        //单文件
        var fileName = "my_file.xml";
        var filePath = Path.Combine("Assets/Lib", fileName);
        File.Copy(filePath, Path.Combine(pathToBuildProject, fileName));
        _pbxProj.AddFileToBuild(_targetGuid, _pbxProj.AddFile(fileName, fileName, PBXSourceTree.Source));
        //------
        #endregion



        //*******************************设置buildsetting*******************************//
        _pbxProj.SetBuildProperty(_targetGuid, "ENABLE_BITCODE", "NO");
        //_pbxProj.AddBuildProperty(_targetGuid,"");
        //_pbxProj.UpdateBuildProperty();

        //_pbxProj.SetBuildProperty(_targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
        //_pbxProj.AddBuildProperty(_targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

        // 设置签名
        //_pbxProj.SetBuildProperty (_targetGuid, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________");
        //_pbxProj.SetBuildProperty (_targetGuid, "PROVISIONING_PROFILE", "********-****-****-****-************");

        //******************************编辑代码****************************************************************
        //修改代码
        //EditorCode(_projPath);


        File.WriteAllText(_projPath, _pbxProj.WriteToString());

        // 保存工程
        //_pbxProj.WriteToFile(_projPath);
    }
コード例 #18
0
    public static void OnPostProcessBuildForiOS(BuildTarget buildTarget, string path)
    {
        string     projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

        proj.ReadFromString(File.ReadAllText(projPath));
        string target = proj.TargetGuidByName("Unity-iPhone");

        proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
        proj.AddBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
        proj.AddFrameworkToProject(target, "AdSupport.framework", false);
        proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false);
        proj.AddFrameworkToProject(target, "AVFoundation.framework", false);
        proj.AddFrameworkToProject(target, "MediaPlayer.framework", false);
        proj.AddFrameworkToProject(target, "CFNetwork.framework", false);
        proj.AddFrameworkToProject(target, "CoreMedia.framework", false);
        proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);
        proj.AddFrameworkToProject(target, "Social.framework", false);
        proj.AddFrameworkToProject(target, "StoreKit.framework", false);
        proj.AddFrameworkToProject(target, "WebKit.framework", false);
        proj.AddFrameworkToProject(target, "EventKit.framework", false);
        proj.AddFrameworkToProject(target, "MessageUI.framework", false);
        proj.AddFrameworkToProject(target, "WatchConnectivity.framework", false);
        proj.AddFrameworkToProject(target, "JavaScriptCore.framework", false);

        proj.AddFileToBuild(target, proj.AddFile("usr/lib/libxml2.dylib", "Frameworks/libxml2.dylib", PBXSourceTree.Sdk));
        proj.AddFileToBuild(target, proj.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));
        proj.AddFileToBuild(target, proj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
        proj.AddFileToBuild(target, proj.AddFile("usr/lib/libsqlite3.0.tbd", "Frameworks/libsqlite3.0.tbd", PBXSourceTree.Sdk));

        File.WriteAllText(projPath, proj.WriteToString());
    }
コード例 #19
0
    static void AddReferenceObjectAssetToResourceGroup(ARReferenceObjectAsset arro, string parentFolderFullPath, string projectRelativePath, PBXProject project)
    {
        ARReferenceObjectResourceContents resourceContents = new ARReferenceObjectResourceContents();

        resourceContents.info         = new ARResourceInfo();
        resourceContents.info.author  = "unity";
        resourceContents.info.version = 1;

        resourceContents.objects           = new ARResourceFilename[1];
        resourceContents.objects [0]       = new ARResourceFilename();
        resourceContents.objects [0].idiom = "universal";

        //add folder for reference image
        string folderToCreate        = arro.objectName + ".arreferenceobject";
        string folderFullPath        = Path.Combine(parentFolderFullPath, folderToCreate);
        string projectRelativeFolder = Path.Combine(projectRelativePath, folderToCreate);

        Directory.CreateDirectory(folderFullPath);
        project.AddFolderReference(folderFullPath, projectRelativeFolder);

        //copy file from texture asset
        string objectPath     = AssetDatabase.GetAssetPath(arro.referenceObject);
        string objectFilename = Path.GetFileName(objectPath);
        var    dstPath        = Path.Combine(folderFullPath, objectFilename);

        File.Copy(objectPath, dstPath, true);
        project.AddFile(dstPath, Path.Combine(projectRelativeFolder, objectFilename));
        resourceContents.objects [0].filename = objectFilename;

        //add contents.json file
        string contentsJsonPath = Path.Combine(folderFullPath, "Contents.json");

        File.WriteAllText(contentsJsonPath, JsonUtility.ToJson(resourceContents, true));
        project.AddFile(contentsJsonPath, Path.Combine(projectRelativeFolder, "Contents.json"));
    }
コード例 #20
0
    public static void OnPostProcessBuild(BuildTarget target, string pathToBuildProject)
    {
        UnityEngine.Debug.Log("===================== appodeal postbuild start ====================");
        projPath = pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        proj     = new PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        targetGuid = proj.TargetGuidByName("Unity-iPhone");

        //frameworks
        string suffix = ".framework";

        proj.AddFrameworkToProject(targetGuid, "Twitter" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "AdSupport" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "AudioToolbox" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "AVFoundation" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreFoundation" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CFNetwork" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreGraphics" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreImage" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreMedia" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreLocation" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreMotion" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreTelephony" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "JavaScriptCore" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "EventKitUI" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "EventKit" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "MediaPlayer" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "MessageUI" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "QuartzCore" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "MobileCoreServices" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "Security" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "StoreKit" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "Social" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "SystemConfiguration" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "Twitter" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "UIKit" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "WebKit" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "CoreBluetooth" + suffix, true);
        proj.AddFrameworkToProject(targetGuid, "GLKit" + suffix, true);

        //libs
        proj.AddFileToBuild(targetGuid, proj.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));
        proj.AddFileToBuild(targetGuid, proj.AddFile("usr/lib/libsqlite3.tbd", "Frameworks/libsqlite3.tbd", PBXSourceTree.Sdk));
        proj.AddFileToBuild(targetGuid, proj.AddFile("usr/lib/libxml2.2.tbd", "Frameworks/libxml2.2.tbd", PBXSourceTree.Sdk));
        proj.AddFileToBuild(targetGuid, proj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));

        //flags
        //proj.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
        proj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Appodeal");
        proj.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks/Plugins/iOS");
        proj.SetBuildProperty(targetGuid, "LIBRARY_SEARCH_PATHS", "$(SRCROOT)/Libraries");


        proj.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");

        File.WriteAllText(projPath, proj.WriteToString());

        UnityEngine.Debug.Log("====================== appodeal postbuild end =====================");
    }
コード例 #21
0
        private static void AddGetSocialChatFramework(ref PBXProject project, string target)
        {
            project.AddFileToBuild(target, project.AddFile("Frameworks/GetSocialChat.embeddedframework/GetSocialChat.framework", "Frameworks/GetSocialChat.embeddedframework/GetSocialChat.framework", PBXSourceTree.Source));
            project.AddFileToBuild(target, project.AddFile("Frameworks/GetSocialChat.embeddedframework/Resources/GetSocialChat.bundle", "Frameworks/GetSocialChat.embeddedframework/Resources/GetSocialChat.bundle", PBXSourceTree.Source));

            // add framework directory to the framework include path
            project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks/GetSocialChat.embeddedframework");
        }
コード例 #22
0
    public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        #if (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
        if (buildTarget == BuildTarget.iOS)
        {
            string projectPath = PBXProject.GetPBXProjectPath(path);

            PBXProject pbxProject = new PBXProject();
            pbxProject.ReadFromFile(projectPath);

            //unity 2019.4.x以上使用
            string target = pbxProject.GetUnityFrameworkTargetGuid();
            //Unity 2019.4.x以下使用
            // string target = pbxProject.GetUnityMainTargetGuid();
            //unity 2018,2017版可使用
            // string target = pbxProject.TargetGuidByName("Unity-iPhone");


            pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
            pbxProject.SetBuildProperty(target, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
            pbxProject.SetBuildProperty(target, "GCC_C_LANGUAGE_STANDARD", "gnu99");

            // pbxProject.RemoveFrameworkFromProject(target,"GoogleUtilities.xcframework");
            // pbxProject.RemoveFrameworkFromProject(target,"nanopb.xcframework");
            // pbxProject.RemoveFrameworkFromProject(target,"PromisesObjC.xcframework");


            // 添加系统框架
            pbxProject.AddFrameworkToProject(target, "VideoToolbox.framework", false);
            pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
            pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-fobjc-arc");
            pbxProject.AddBuildProperty(target, "OTHER_LDFLAGS", "-l\"c++abi\"");

            // 加了还是错误,需要删除之后,clean项目之后,重新手动添加。所以不加这个配置
            // pbxProject.AddBuildProperty(target,"RUNPATH_SEARCH_PATHS","@executable_path/Frameworks");

            pbxProject.AddFileToBuild(target, pbxProject.AddFile("usr/lib/libxml2.tbd", "Libraries/libxml2.tbd", PBXSourceTree.Sdk));
            pbxProject.AddFileToBuild(target, pbxProject.AddFile("usr/lib/libresolv.9.tbd", "Libraries/libresolv.9.tbd", PBXSourceTree.Sdk));
            pbxProject.AddFileToBuild(target, pbxProject.AddFile("usr/lib/libbz2.1.0.tbd", "Libraries/libbz2.1.0.tbd", PBXSourceTree.Sdk));

            // 获取主 target
            string mainTarget = pbxProject.GetUnityMainTargetGuid();
            pbxProject.AddFileToBuild(mainTarget, pbxProject.AddFile("Frameworks/AnyThinkAds/Plugins/iOS/Core/AnyThinkSDK.bundle", "Frameworks/AnyThinkAds/Plugins/iOS/Core/AnyThinkSDK.bundle", PBXSourceTree.Sdk));
            pbxProject.AddFileToBuild(mainTarget, pbxProject.AddFile("Frameworks/AnyThinkAds/Plugins/iOS/pangle/BUAdSDK.bundle", "Frameworks/AnyThinkAds/Plugins/iOS/pangle/BUAdSDK.bundle", PBXSourceTree.Sdk));



            pbxProject.WriteToFile(projectPath);

            var           plistPath = Path.Combine(path, "Info.plist");
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            plist.root.SetString("GADApplicationIdentifier", "ca-app-pub-9488501426181082/7319780494");
            plist.root.SetBoolean("GADIsAdManagerApp", true);
            plist.WriteToFile(plistPath);
        }
        #endif
    }
コード例 #23
0
ファイル: iOSXcodeSet.cs プロジェクト: webloverand/AFramework
        private static void AddFolderBuild(PBXProject pbx, string targetGUID, string xcodePath, string root)
        {
            //获得源文件下所有目录文件
            string currDir = Path.Combine(xcodePath, root);

            if (root.EndsWith(".framework", System.StringComparison.Ordinal) || root.EndsWith(".bundle", System.StringComparison.Ordinal))
            {
#if UNITY_2019_2_OR_NEWER
                string target = pbx.TargetGuidByName(pbx.GetUnityMainTargetGuid());
#else
                string target = pbx.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
                Debug.LogFormat("add framework or bundle to build:{0}->{1}", currDir, root);
                pbx.AddFileToBuild(target, pbx.AddFile(currDir, root, PBXSourceTree.Source));
                return;
            }
            List <string> folders = new List <string>(Directory.GetDirectories(currDir));
            foreach (string folder in folders)
            {
                string name       = Path.GetFileName(folder);
                string t_path     = Path.Combine(currDir, name);
                string t_projPath = Path.Combine(root, name);
                if (folder.EndsWith(".framework", System.StringComparison.Ordinal) || folder.EndsWith(".bundle", System.StringComparison.Ordinal))
                {
#if UNITY_2019_2_OR_NEWER
                    string target = pbx.TargetGuidByName(pbx.GetUnityMainTargetGuid());
#else
                    string target = pbx.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
                    Debug.LogFormat("add framework or bundle to build:{0}->{1}", t_path, t_projPath);
                    pbx.AddFileToBuild(target, pbx.AddFile(t_path, t_projPath, PBXSourceTree.Source));
                    AutoAddSearchPath(pbx, targetGUID, xcodePath, t_path);
                }
                else
                {
                    AddFolderBuild(pbx, targetGUID, xcodePath, t_projPath);
                }
            }
            List <string> files = new List <string>(Directory.GetFiles(currDir));
            foreach (string file in files)
            {
                if (NeedCopy(file))
                {
                    string name       = Path.GetFileName(file);
                    string t_path     = Path.Combine(currDir, name);
                    string t_projPath = Path.Combine(root, name);
#if UNITY_2019_2_OR_NEWER
                    string target = pbx.TargetGuidByName(pbx.GetUnityMainTargetGuid());
#else
                    string target = pbx.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
                    pbx.AddFileToBuild(target, pbx.AddFile(t_path, t_projPath, PBXSourceTree.Source));
                    AutoAddSearchPath(pbx, targetGUID, xcodePath, t_path);
                    AFLogger.d("add file to build:" + Path.Combine(root, file));
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Writes properties to the XCode framework
        /// </summary>
        /// <param name="pbxProject"></param>
        /// <param name="targetGUID"></param>
        /// <param name="pbxProjectPath"></param>
        /// <param name="pluginPath"></param>
        private static void WritePropertiesToFramework(PBXProject pbxProject, string targetGUID, string pbxProjectPath, string pluginPath, bool forceAlwaysEmbedSwiftStandardLibraries)
        {
            // Full Path to copy from
            Debug.Log("[MMNVBuildPostProcessor] Adding properties to XCode framework");
            Debug.Log("[MMNVBuildPostProcessor] Plugin path : " + pluginPath);

            pbxProject.AddFrameworkToProject(targetGUID, "CoreHaptics.framework", false);
            pbxProject.SetBuildProperty(targetGUID, "SWIFT_VERSION", "5.1");
            pbxProject.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO");

            if (forceAlwaysEmbedSwiftStandardLibraries)
            {
                pbxProject.SetBuildProperty(targetGUID, "EMBEDDED_CONTENT_CONTAINS_SWIFT", "YES");
                pbxProject.SetBuildProperty(targetGUID, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
            }
            pbxProject.SetBuildProperty(targetGUID, "CLANG_ENABLE_MODULES", "YES");
            pbxProject.SetBuildProperty(targetGUID, "SWIFT_INCLUDE_PATHS", pluginPath);
            pbxProject.SetBuildProperty(targetGUID, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks");

            // if you're using the FB SDK and are having issues with your build pipeline, you may want to uncomment these lines (part 1/2) :
            // proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-lxml2");
            // proj.AddFrameworkToProject(targetGUID, "libxml2.dylib", true);

            // we add a module reference to the pbx project
            Debug.Log("[MMNVBuildPostProcessor] Add module reference : " + _moduleFileUnityPath + " -> " + _moduleFileXCodePath);
            string file_guid = pbxProject.AddFile(_moduleFileXCodePath,
                                                  _moduleFileXCodePath,
                                                  PBXSourceTree.Source);

            Debug.Log("[MMNVBuildPostProcessor] Module GUID : " + file_guid);
            pbxProject.AddFileToBuild(targetGUID, file_guid);
            File.WriteAllText(pbxProjectPath, pbxProject.WriteToString());

            // we copy the module file to the project
            string projFileDir    = System.IO.Path.GetDirectoryName(pbxProjectPath);
            string moduleFilePath = Application.dataPath + SEPARATOR + ".." + SEPARATOR + _moduleFileUnityPath;
            string destination    = projFileDir + SEPARATOR + ".." + SEPARATOR + pluginPath + _moduleFileName;

            if (!Directory.Exists(Path.GetDirectoryName(destination)))
            {
                Debug.Log("[MMNVBuildPostProcessor] Creating directory " + destination);
                Directory.CreateDirectory(Path.GetDirectoryName(destination));
            }
            Debug.Log("[MMNVBuildPostProcessor] Copy module file to project : " + moduleFilePath + " -> " + destination);
            System.IO.File.Copy(moduleFilePath, destination, true);

            Debug.Log("[MMNVBuildPostProcessor] Copy module file to project : " + moduleFilePath + " -> " + destination);
            string headerGUID = pbxProject.AddFile(_headerFileUnityPath,
                                                   _headerFileXCodePath,
                                                   PBXSourceTree.Source);

            pbxProject.AddFileToBuild(targetGUID, headerGUID);
            pbxProject.AddPublicHeaderToBuild(targetGUID, headerGUID);

            Debug.Log("[MMNVBuildPostProcessor] Framework complete");
        }
コード例 #25
0
        public void AddingDuplicateFilerefReturnsExisting()
        {
            ResetGuidGenerator();
            PBXProject proj = ReadPBXProject();

            string fileGuid = proj.AddFile("relative/path1.cc", "Classes/path1.cc", PBXSourceTree.Source);

            Assert.AreEqual(fileGuid, proj.AddFile("relative/path1.cc", "Classes/path1.cc", PBXSourceTree.Source));
            Assert.AreEqual(fileGuid, proj.AddFile("relative/path2.cc", "Classes/path1.cc", PBXSourceTree.Source));
        }
コード例 #26
0
    private static void UpdateProject(BuildTarget buildTarget, string projectPath)
    {
        PBXProject project = new PBXProject();

        project.ReadFromString(File.ReadAllText(projectPath));

        string targetId = project.TargetGuidByName(PBXProject.GetUnityTargetName());

        // Required Frameworks
        project.AddFrameworkToProject(targetId, "CoreTelephony.framework", false);
        project.AddFrameworkToProject(targetId, "EventKit.framework", false);
        project.AddFrameworkToProject(targetId, "EventKitUI.framework", false);
        project.AddFrameworkToProject(targetId, "MediaPlayer.framework", false);
        project.AddFrameworkToProject(targetId, "MessageUI.framework", false);
        project.AddFrameworkToProject(targetId, "QuartzCore.framework", false);
        project.AddFrameworkToProject(targetId, "SystemConfiguration.framework", false);
        project.AddFrameworkToProject(targetId, "Security.framework", false);
        project.AddFrameworkToProject(targetId, "MobileCoreServices.framework", false);
        project.AddFrameworkToProject(targetId, "PassKit.framework", false);
        project.AddFrameworkToProject(targetId, "Social.framework", false);
        project.AddFrameworkToProject(targetId, "CoreData.framework", false);
        project.AddFrameworkToProject(targetId, "AdSupport.framework", false);
        project.AddFrameworkToProject(targetId, "StoreKit.framework", false);

        #if UNITY_2017_1_OR_NEWER
        if (project.ContainsFramework(targetId, "iAd.framework"))
        {
        #else
        if (project.HasFramework("iAd.framework"))
        {
        #endif
            project.RemoveFrameworkFromProject(targetId, "iAd.framework");
        }


        project.AddFileToBuild(targetId, project.AddFile("usr/lib/libz.1.2.5.dylib", "Frameworks/libz.1.2.5.dylib", PBXSourceTree.Sdk));
        project.AddFileToBuild(targetId, project.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", PBXSourceTree.Sdk));
        project.AddFileToBuild(targetId, project.AddFile("usr/lib/libsqlite3.dylib", "Frameworks/libsqlite3.dylib", PBXSourceTree.Sdk));
        project.AddFileToBuild(targetId, project.AddFile("usr/lib/libsqlite3.0.dylib", "Frameworks/libsqlite3.0.dylib", PBXSourceTree.Sdk));
        project.AddFileToBuild(targetId, project.AddFile("usr/lib/libxml2.dylib", "Frameworks/libxml2.dylib", PBXSourceTree.Sdk));

        // Optional Frameworks
        project.AddFrameworkToProject(targetId, "Webkit.framework", true);
        project.AddFrameworkToProject(targetId, "JavaScriptCore.framework", true);
        project.AddFrameworkToProject(targetId, "WatchConnectivity.framework", true);

        // For 3.0 MP classes
        project.AddBuildProperty(targetId, "OTHER_LDFLAGS", "-ObjC");
        project.AddBuildProperty(targetId, "OTHER_LDFLAGS", "-lxml2");
        project.SetBuildProperty(targetId, "ENABLE_BITCODE", "NO");

        File.WriteAllText(projectPath, project.WriteToString());
    }
}
コード例 #27
0
        public static void OnPostProcessBuild(BuildTarget target, string path)
        {
            if (BuildTarget.iOS != target)
            {
                return;
            }

            IOSProjectInitData data = IOSProjectInitData.Load();

            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject pbx      = new PBXProject();

            pbx.ReadFromString(File.ReadAllText(projPath));
            string guid = pbx.TargetGuidByName("Unity-iPhone");

            pbx.AddFrameworkToProject(guid, "CoreTelephony.framework", false);
            pbx.AddFrameworkToProject(guid, "StoreKit.framework", false);
            pbx.AddFrameworkToProject(guid, "AdSupport.framework", false);
            pbx.AddFrameworkToProject(guid, "WebKit.framework", false);
            pbx.AddFrameworkToProject(guid, "MessageUI.framework", false);
            pbx.AddFrameworkToProject(guid, "GLKit.framework", false);
            pbx.AddFrameworkToProject(guid, "MobileCoreService.framework", false);

            pbx.AddFileToBuild(guid, pbx.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));
            pbx.AddFileToBuild(guid, pbx.AddFile("usr/lib/libc++.tbd", "Frameworks/libc++.tbd", PBXSourceTree.Sdk));
            pbx.AddFileToBuild(guid, pbx.AddFile("usr/lib/libicucore.tbd", "Frameworks/libicucore.tbd", PBXSourceTree.Sdk));
            pbx.AddFileToBuild(guid, pbx.AddFile("usr/lib/libsqlite3.0.tbd", "Frameworks/libsqlite3.0.tbd", PBXSourceTree.Sdk));


            pbx.SetBuildProperty(guid, "ENABLE_BITCODE", "NO");
            pbx.AddBuildProperty(guid, "OTHER_LDFLAGS", "-force_load $(PROJECT_DIR)/Libraries/Plugins/iOS/WeChat/libWeChatSDK.a");
            pbx.AddBuildProperty(guid, "OTHER_LDFLAGS", "-ObjC");
            //$(PROJECT_DIR) / Libraries / Plugins / iOS / WeChat / libWeChatSDK.a

            //有米SDK需要内容


            File.WriteAllText(projPath, pbx.WriteToString());

            ////修改PList
            string          plistPath   = path + "/Info.plist";
            InfoPListEditor pListEditor = new InfoPListEditor(plistPath);

            foreach (string urlScheme in data.urlSchemes)
            {
                pListEditor.AddUrlScheme("yfy", urlScheme);
            }
            foreach (string whiteUrlScheme in data.whiteSchemeList)
            {
                pListEditor.AddLSApplicationQueriesScheme(whiteUrlScheme);
            }
            pListEditor.Save();
        }
コード例 #28
0
        private static void UpdateIOSProject(string path)
        {
            PBXProject proj     = new PBXProject();
            string     projPath = PBXProject.GetPBXProjectPath(path);

            proj.ReadFromFile(projPath);

            string mainTargetGuid           = string.Empty;
            string unityFrameworkTargetGuid = string.Empty;

#if UNITY_2019_3_OR_NEWER
            mainTargetGuid           = proj.GetUnityMainTargetGuid();
            unityFrameworkTargetGuid = proj.GetUnityFrameworkTargetGuid();
            string frameworksPath = path + "/Frameworks/Plugins/iOS/Yodo1Ads/";
            if (Directory.Exists(frameworksPath))
            {
                string[] directories = Directory.GetDirectories(frameworksPath, "*.bundle", SearchOption.AllDirectories);
                for (int i = 0; i < directories.Length; i++)
                {
                    var dirPath    = directories[i];
                    var suffixPath = dirPath.Substring(path.Length + 1);
                    var fileGuid   = proj.AddFile(suffixPath, suffixPath);
                    proj.AddFileToBuild(mainTargetGuid, fileGuid);

                    fileGuid = proj.FindFileGuidByProjectPath(suffixPath);
                    if (fileGuid != null)
                    {
                        proj.RemoveFileFromBuild(unityFrameworkTargetGuid, fileGuid);
                    }
                }
            }
#else
            mainTargetGuid           = proj.TargetGuidByName("Unity-iPhone");
            unityFrameworkTargetGuid = mainTargetGuid;
#endif

#if UNITY_2019_3_OR_NEWER
            var unityFrameworkGuid = proj.FindFileGuidByProjectPath("UnityFramework.framework");
            if (unityFrameworkGuid == null)
            {
                unityFrameworkGuid = proj.AddFile("UnityFramework.framework", "UnityFramework.framework");
                proj.AddFileToBuild(mainTargetGuid, unityFrameworkGuid);
            }
            proj.AddFrameworkToProject(mainTargetGuid, "UnityFramework.framework", false);
            proj.SetBuildProperty(mainTargetGuid, "ENABLE_BITCODE", "NO");
#endif

            proj.SetBuildProperty(unityFrameworkTargetGuid, "ENABLE_BITCODE", "NO");
            proj.AddBuildProperty(unityFrameworkTargetGuid, "OTHER_LDFLAGS", "-ObjC -lxml2");

            // rewrite to file
            File.WriteAllText(projPath, proj.WriteToString());
        }
コード例 #29
0
ファイル: XCodeConfig.cs プロジェクト: h1014179971/AdsDemo
    private static void AddFolderBuild(PBXProject proj, string xcodePath, string root)
    {
        //获得源文件下所有目录文件
        string currDir = Path.Combine(xcodePath, root);

        if (root.EndsWith(".framework") || root.EndsWith(".bundle"))
        {
            string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
            Debug.LogFormat("add framework or bundle to build:{0}->{1}", currDir, root);
            string fileGuid = proj.AddFile(currDir, root, PBXSourceTree.Source);
            proj.AddFileToBuild(target, fileGuid);
            AddEmbedFarmeworks(proj, target, fileGuid, root);
            return;
        }
        List <string> folders = new List <string>(Directory.GetDirectories(currDir));

        foreach (string folder in folders)
        {
            string name       = Path.GetFileName(folder);
            string t_path     = Path.Combine(currDir, name);
            string t_projPath = Path.Combine(root, name);
            if (folder.EndsWith(".framework") || folder.EndsWith(".bundle"))
            {
                string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
                Debug.LogFormat("add framework or bundle to build:{0}->{1}", t_path, t_projPath);
                string fileGuid = proj.AddFile(t_path, t_projPath, PBXSourceTree.Source);
                proj.AddFileToBuild(target, fileGuid);
                AutoAddSearchPath(proj, xcodePath, t_path);
                AddEmbedFarmeworks(proj, target, fileGuid, t_projPath);
            }
            else
            {
                AddFolderBuild(proj, xcodePath, t_projPath);
            }
        }
        List <string> files = new List <string>(Directory.GetFiles(currDir));

        foreach (string file in files)
        {
            if (NeedCopy(file))
            {
                string name       = Path.GetFileName(file);
                string t_path     = Path.Combine(currDir, name);
                string t_projPath = Path.Combine(root, name);
                string target     = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
                string fileGuid   = proj.AddFile(t_path, t_projPath, PBXSourceTree.Source);
                proj.AddFileToBuild(target, fileGuid);
                AutoAddSearchPath(proj, xcodePath, t_path);
                Debug.Log("add file to build:" + Path.Combine(root, file));
                AddEmbedFarmeworks(proj, target, fileGuid, t_projPath);
            }
        }
    }
コード例 #30
0
    private static void AddExternalFramework(string path, string framework)
    {
        string srcPath = path + "/" + framework;
        string dstPath = Path.Combine(_path, "Frameworks/" + framework);

        CopyAndReplaceDirectory(srcPath, dstPath);

        string frameworkGuid = _project.AddFile("Frameworks/" + framework, "Frameworks/" + framework, PBXSourceTree.Source);

        _project.AddFileToBuild(_target, frameworkGuid);

        AddFramework(framework);
    }
        public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            PBXProject project        = new PBXProject();
            string     pbxProjectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

            project.ReadFromString(File.ReadAllText(pbxProjectPath));

            string target     = project.TargetGuidByName(PBXProject.GetUnityTargetName());
            string testTarget = project.TargetGuidByName(PBXProject.GetUnityTestTargetName());

            // Linker flags.
            project.SetBuildProperty(target, "ARCHS", "$(ARCHS_STANDARD)");
            project.SetBuildProperty(testTarget, "ARCHS", "$(ARCHS_STANDARD)");
            project.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC");
            project.AddBuildProperty(testTarget, "OTHER_LDFLAGS", "-ObjC");
            project.AddBuildProperty(target, "OTHER_LDFLAGS", "-lz");
            project.AddBuildProperty(testTarget, "OTHER_LDFLAGS", "-lz");

            // Search paths.
            project.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
            project.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks");

            // Framework dependencies.
            project.AddFrameworkToProject(target, "AVFoundation.framework", true);
            project.AddFrameworkToProject(target, "Accelerate.framework", true);
            project.AddFrameworkToProject(target, "CFNetwork.framework", true);
            project.AddFrameworkToProject(target, "CoreBluetooth.framework", true);
            project.AddFrameworkToProject(target, "CoreText.framework", true);
            project.AddFrameworkToProject(target, "MediaPlayer.framework", true);
            project.AddFrameworkToProject(target, "MediaToolbox.framework", true);
            project.AddFrameworkToProject(target, "Metal.framework", true);
            project.AddFrameworkToProject(target, "Security.framework", true);
            project.AddFrameworkToProject(target, "SystemConfiguration.framework", true);

            // Dynamic library dependencies.
            string sqlite3dylibGuid = project.AddFile("usr/lib/libsqlite3.dylib",
                                                      "usr/lib/libsqlite3.dylib", PBXSourceTree.Sdk);

            project.AddFileToBuild(target, sqlite3dylibGuid);
            string libCppdylibGuid = project.AddFile("usr/lib/libc++.dylib",
                                                     "usr/lib/libc++.dylib", PBXSourceTree.Sdk);

            project.AddFileToBuild(target, libCppdylibGuid);

            File.WriteAllText(pbxProjectPath, project.WriteToString());
        }
コード例 #32
0
		public static void OnPostProcessBuild( BuildTarget buildTarget, string buildPath )
		{
			#if UNITY_5
			if (buildTarget == BuildTarget.iOS)
			#else
			if (buildTarget == BuildTarget.iPhone)
			#endif
			{
				var projPath = PBXProject.GetPBXProjectPath( buildPath );
				PBXProject proj = new PBXProject();
				proj.ReadFromString( File.ReadAllText( projPath ) );
				var targetGuid = proj.TargetGuidByName( "Unity-iPhone" );

				var instance = ScriptableObject.CreateInstance<ICadePluginPath>(); 
				var pluginPath = Path.GetDirectoryName( AssetDatabase.GetAssetPath( MonoScript.FromScriptableObject( instance ) ) );
				ScriptableObject.DestroyImmediate( instance );

				var targetPath = Path.Combine( "Libraries", pluginPath.Substring( 7 ) );
				Directory.CreateDirectory( Path.Combine( buildPath, targetPath ) );

				foreach (var fileName in sourceFiles)
				{
					var sourcePath = Path.Combine( pluginPath, fileName );
					var targetFile = Path.Combine( targetPath, fileName );
					File.Copy( sourcePath, Path.Combine( buildPath, targetFile ), true );
					proj.AddFileToBuild( targetGuid, proj.AddFile( targetFile, targetFile, PBXSourceTree.Source ) );
				}

				File.WriteAllText( projPath, proj.WriteToString() );
			}
		}