Esempio n. 1
29
    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
    }
    private static void AddFrameworks(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");

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

        // add frameworks
        proj.AddFrameworkToProject(target, "AdSupport.framework", true);
        proj.AddFrameworkToProject(target, "AddressBook.framework", true);
        proj.AddFrameworkToProject(target, "libsqlite3.0.dylib", false);


        string[] plistFiles = Directory.GetFiles(Application.dataPath, "GoogleService-Info.plist", SearchOption.AllDirectories);
        foreach (string customPlistPath in plistFiles)
        {
            proj.AddFileToBuild(target, proj.AddFile(customPlistPath, "GoogleService-Info.plist", PBXSourceTree.Source));
        }

        File.WriteAllText(projPath, proj.WriteToString());
    }
Esempio n. 3
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        var        projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

        proj.ReadFromFile(projPath);
#if UNITY_2019_3_OR_NEWER
        string guid = proj.GetUnityFrameworkTargetGuid();
#else
        string guid = proj.TargetGuidByName("Unity-iPhone");
#endif

        proj.AddBuildProperty(guid, "OTHER_LDFLAGS", "-ObjC");
        proj.AddFrameworkToProject(guid, "VideoToolbox.framework", false);
        proj.AddFrameworkToProject(guid, "GLKit.framework", false);
        proj.AddFrameworkToProject(guid, "Network.framework", false);
        // libwebrtc.a には新しい libvpx が、libiPhone-lib.a には古い libvpx が入っていて、
        // デフォルトのリンク順序だと古い libvpx が使われてしまう。
        // それを回避するために libiPhone-lib.a を削除して新しく追加し直すことで
        // リンク順序を変えてやる。
        string fileGuid = proj.FindFileGuidByProjectPath("Libraries/libiPhone-lib.a");
        proj.RemoveFileFromBuild(guid, fileGuid);
        proj.AddFileToBuild(guid, fileGuid);

        proj.WriteToFile(projPath);
    }
    private static void PostProcessBuild(string path)
    {
        #region pbxproj
        string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

        // PBXProject class represents a project build settings file,
        // here is how to read that in.
        PBXProject proj = new PBXProject();
        proj.ReadFromFile(projPath);

        // This is the Xcode target in the generated project
        string target = proj.TargetGuidByName("Unity-iPhone");

        // Write PBXProject object back to the file
        //proj.AddBuildProperty(target, "ENABLE_BITCODE", "NO");

        proj.AddFrameworkToProject(target, "VideoToolbox.framework", false);
        proj.AddFrameworkToProject(target, "libz.tbd", false);
        proj.AddFrameworkToProject(target, "libbz2.tbd", false);
        proj.AddFrameworkToProject(target, "libiconv.tbd", false);

        proj.WriteToFile(projPath);
        #endregion

        #region info plist
        string plistPath = path + "/Info.plist";

        PlistDocument plist = new PlistDocument();
        plist.ReadFromFile(plistPath);
        plist.root.SetString("NSMicrophoneUsageDescription", "User can record himself and video");
        plist.WriteToFile(plistPath);
        #endregion
    }
Esempio n. 5
0
    public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget == BuildTarget.iOS)
        {
#if UNITY_IPHONE
            // Plist File Setting.
            string        plistPath = pathToBuiltProject + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            PlistElementDict rootDict = plist.root;

            var iTSAppUsesNonExemptEncryptionKey = "ITSAppUsesNonExemptEncryption";
            rootDict.SetString(iTSAppUsesNonExemptEncryptionKey, "false");

            // Xcode Project File Setting.
            string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

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

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

            proj.AddFrameworkToProject(target, "Accelerate.framework", false);
            proj.AddFrameworkToProject(target, "ARKit.framework", false);

//            string file = proj.FindFileGuidByRealPath( "Frameworks/Plugins/MaxstAR3D.bundle" );
//            proj.RemoveFileFromBuild( target, file );
//            proj.RemoveFile( file );

            File.WriteAllText(projPath, proj.WriteToString());
#endif
        }
    }
Esempio n. 6
0
    public static void OnPreProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target == BuildTarget.iOS)
        {
            var path       = PBXProject.GetPBXProjectPath(pathToBuiltProject);
            var pbxProject = new PBXProject();
            pbxProject.ReadFromFile(path);
            var targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
#if USE_IOS_SIMULATOR
            RemoveFileFromProject(pbxProject, targetGuid, "libassimp.release.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libirrxml.release.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libminizip.release.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libstb_image.release.a");
#else
            RemoveFileFromProject(pbxProject, targetGuid, "libassimp.debug.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libirrxml.debug.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libminizip.debug.a");
            RemoveFileFromProject(pbxProject, targetGuid, "libstb_image.debug.a");
            pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
#endif
            pbxProject.AddFrameworkToProject(targetGuid, "libz.dylib", true);
            pbxProject.AddFrameworkToProject(targetGuid, "libz.tbd", true);
            pbxProject.WriteToFile(path);
#if USE_IOS_FILES_SHARING
            var plistPath = pathToBuiltProject + "/info.plist";
            var plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            var dict = plist.root.AsDict();
            dict.SetBoolean("UIFileSharingEnabled", true);
            plist.WriteToFile(plistPath);
#endif
        }
    }
Esempio n. 7
0
        static void ChangeProject(string pathToBuildProject)
        {
            string path = PBXProject.GetPBXProjectPath(pathToBuildProject);

            PBXProject pbx = new PBXProject();

            pbx.ReadFromString(File.ReadAllText(path));

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

            if (!string.IsNullOrEmpty(target))
            {
                pbx.AddFrameworkToProject(target, "AdSupport.framework", true);
                pbx.AddFrameworkToProject(target, "CoreTelephony.framework", true);
                pbx.AddFrameworkToProject(target, "GameKit.framework", true);
                pbx.AddFrameworkToProject(target, "MobileCoreServices.framework", true);
                pbx.AddFrameworkToProject(target, "SystemConfiguration.framework", true);

                //pbx.AddFileToBuild(target, pbx.AddFile("IGGSDK.framework", "Frameworks/IGGSDK.framework", PBXSourceTree.Source));

                pbx.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
                pbx.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)");

                pbx.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

                // 技术部文档要求用-all_load,但是wwise会报链接时会报符号重复.后面有需要可以使用-force_load xxx.a
                //pbx.SetBuildProperty(target, "OTHER_LDFLAGS", "-all_load");
            }

            File.WriteAllText(path, pbx.WriteToString());
        }
Esempio n. 8
0
    //修改PBXProject
    static void ModifyPBXProject(string path)
    {
        // Read.
        string     projectPath = PBXProject.GetPBXProjectPath(path);
        PBXProject project     = new PBXProject();

        project.ReadFromString(File.ReadAllText(projectPath));
        string targetName = PBXProject.GetUnityTargetName();
        string targetGUID = project.TargetGuidByName(targetName);

        // Frameworks
        project.AddFrameworkToProject(targetGUID, "WebKit.framework", false);
        project.AddFrameworkToProject(targetGUID, "MobileCoreServices.framework", false);
        project.AddFrameworkToProject(targetGUID, "CoreFoundation.framework", false);

        //属性
        project.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO");
        project.SetTargetAttributes("ProvisioningStyle", "Manual");

        //这里替换Replace("_", "-"),Replace("_", " ") 由于我们用了"-"作为分割识别符所以要改成了"_", 还有就是参数传递是已" "来分割的,所以当我们参数中自身就带了空格,那么就会截断,所以参数里面用"_"替换了" ",这里再替换回来
        project.SetBuildProperty(targetGUID, "PROVISIONING_PROFILE", argDic["PROVISIONING_PROFILE"].Replace("_", "-"));
        project.SetBuildProperty(targetGUID, "CODE_SIGN_IDENTITY", argDic["CODE_SIGN_IDENTITY"].Replace("_", " "));
        project.SetBuildProperty(targetGUID, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", argDic["CODE_SIGN_IDENTITY"].Replace("_", " "));
        project.SetBuildProperty(targetGUID, "DEVELOPMENT_TEAM", argDic["DEVELOPMENT_TEAM"]);

        File.WriteAllText(projectPath, project.WriteToString());
    }
    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());
    }
Esempio n. 10
0
    public void OnPostprocessBuild(BuildTarget target, string path)
    {
#if UNITY_EDITOR_OSX
        var buildTarget = target;
        var buildPath   = path;
#endif
#endif
#if UNITY_EDITOR_OSX
        if (buildTarget == BuildTarget.iOS)
        {
            var pbxProject     = new PBXProject();
            var pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath);
            pbxProject.ReadFromFile(pbxProjectPath);
            var targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
            pbxProject.AddFrameworkToProject(targetGuid, "libz.dylib", true);
            pbxProject.AddFrameworkToProject(targetGuid, "libz.tbd", true);
            pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");
            pbxProject.WriteToFile(pbxProjectPath);
            if (_iosFileSharingEnabled)
            {
                var plistPath = buildPath + "/info.plist";
                var plist     = new PlistDocument();
                plist.ReadFromFile(plistPath);
                var dict = plist.root.AsDict();
                dict.SetBoolean("UIFileSharingEnabled", true);
                plist.WriteToFile(plistPath);
            }
        }
#endif
    }
Esempio n. 11
0
    private static void AddFrameworks(PBXProject project, string target)
    {
        const bool weak = false;

        project.AddFrameworkToProject(target, "MobileCoreServices.framework", weak);
        project.AddFrameworkToProject(target, "Security.framework", weak);
    }
Esempio n. 12
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);
    }
Esempio n. 13
0
    private static void RunPostBuildScript(BuildTarget target, bool preBuild, string projectPath = "")
    {
        if (target == BuildTarget.Android)
        {
            UnityEngine.Debug.Log("[Adjust]: Starting to perform post build tasks for Android platform.");
            RunPostProcessTasksAndroid();
        }
        else if (target == BuildTarget.iOS)
        {
#if UNITY_IOS
            UnityEngine.Debug.Log("[Adjust]: Starting to perform post build tasks for iOS platform.");

            string xcodeProjectPath = projectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject xcodeProject = new PBXProject();
            xcodeProject.ReadFromFile(xcodeProjectPath);

            // The Adjust SDK needs two frameworks to be added to the project:
            // - AdSupport.framework
            // - iAd.framework

#if UNITY_2019_3_OR_NEWER
            string xcodeTarget = xcodeProject.GetUnityFrameworkTargetGuid();
#else
            string xcodeTarget = xcodeProject.TargetGuidByName("Unity-iPhone");
#endif

            UnityEngine.Debug.Log("[Adjust]: Adding AdSupport.framework to Xcode project.");
            xcodeProject.AddFrameworkToProject(xcodeTarget, "AdSupport.framework", true);
            UnityEngine.Debug.Log("[Adjust]: AdSupport.framework added successfully.");

            UnityEngine.Debug.Log("[Adjust]: Adding iAd.framework to Xcode project.");
            xcodeProject.AddFrameworkToProject(xcodeTarget, "iAd.framework", true);
            UnityEngine.Debug.Log("[Adjust]: iAd.framework added successfully.");

            UnityEngine.Debug.Log("[Adjust]: Adding CoreTelephony.framework to Xcode project.");
            xcodeProject.AddFrameworkToProject(xcodeTarget, "CoreTelephony.framework", true);
            UnityEngine.Debug.Log("[Adjust]: CoreTelephony.framework added successfully.");

            // The Adjust SDK needs to have Obj-C exceptions enabled.
            // GCC_ENABLE_OBJC_EXCEPTIONS=YES

            UnityEngine.Debug.Log("[Adjust]: Enabling Obj-C exceptions by setting GCC_ENABLE_OBJC_EXCEPTIONS value to YES.");
            xcodeProject.AddBuildProperty(xcodeTarget, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");

            UnityEngine.Debug.Log("[Adjust]: Obj-C exceptions enabled successfully.");

            // The Adjust SDK needs to have -ObjC flag set in other linker flags section because of it's categories.
            // OTHER_LDFLAGS -ObjC

            UnityEngine.Debug.Log("[Adjust]: Adding -ObjC flag to other linker flags (OTHER_LDFLAGS).");
            xcodeProject.AddBuildProperty(xcodeTarget, "OTHER_LDFLAGS", "-ObjC");

            UnityEngine.Debug.Log("[Adjust]: -ObjC successfully added to other linker flags.");

            // Save the changes to Xcode project file.
            xcodeProject.WriteToFile(xcodeProjectPath);
#endif
        }
    }
Esempio n. 14
0
 private static void AddLibs(string targetGuid, PBXProject proj)
 {
     proj.AddFrameworkToProject(targetGuid, "libz.tbd", false);
     proj.AddFrameworkToProject(targetGuid, "libsqlite3.0.dylib", false);
     proj.AddFrameworkToProject(targetGuid, "libc++.dylib", false);
     proj.AddFrameworkToProject(targetGuid, "libstdc++.6.0.9.tbd", false);
 }
Esempio n. 15
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
                #if UNITY_IOS
        if (buildTarget == BuildTarget.iOS)
        {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

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

            proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
            proj.SetBuildProperty(target, "PROVISIONING_PROFILE",
                                  "********-*****-****-****-************");

            proj.AddFrameworkToProject(target, "libz.1.2.5.tbd", true);
            proj.AddFrameworkToProject(target, "libsqlite3.tbd", true);

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

//			EditorPlist (path);
//			EditorFile (path);
//          EditorCode (path);
        }
                #endif
    }
Esempio n. 16
0
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }

        // Initialize PBXProject
        var        projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromFile(projectPath);

        string targetGuid = pbxProject.GetUnityFrameworkTargetGuid();

        // Add build settings
        // TODO: Add if required

        // Add frameworks
        pbxProject.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "MobileCoreServices.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "Security.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "WebKit.framework", false);

        pbxProject.WriteToFile(projectPath);
    }
Esempio n. 17
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            // Handle xcodeproj
            string     projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
            PBXProject proj     = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));
            string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

            proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

            proj.AddFrameworkToProject(target, "libxml2.tbd", false);
            proj.AddFrameworkToProject(target, "libz.tbd", false);
            proj.AddFrameworkToProject(target, "ReplayKit.framework", false);
            proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);

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

            // Handle plist
            string        plistPath = pathToBuiltProject + "/Info.plist";
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));
            PlistElementDict rootDict = plist.root;
            rootDict.SetBoolean("UIFileSharingEnabled", true);
            rootDict.SetString("NSPhotoLibraryAddUsageDescription", "是否允许此App访问您的相册?");

            File.WriteAllText(plistPath, plist.WriteToString());
        }
    }
        public static void OnPostprocessBuildHandler(BuildTarget buildTarget, string path)
        {
            var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            var proj = new PBXProject();

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

#if UNITY_2019_3_OR_NEWER
            var target = proj.GetUnityFrameworkTargetGuid();
#else
            var target = proj.TargetGuidByName("Unity-iPhone");
#endif

            proj.AddFrameworkToProject(target, "AdSupport.framework", true);
            proj.AddFrameworkToProject(target, "AppTrackingTransparency.framework", true);

            var plistPath = path + "/Info.plist";
            var plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            var rootDict = plist.root;

            rootDict.SetString("NSUserTrackingUsageDescription", USER_TRACK_USAGE_DESCRIPTION);

            File.WriteAllText(plistPath, plist.WriteToString());
            File.WriteAllText(projPath, proj.WriteToString());
        }
Esempio n. 19
0
        private static void ProcessProject(string path)
        {
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();

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

            //获取当前项目名字
            string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

            //对所有的编译配置设置选项
            //                proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
            proj.SetBuildProperty(target, "PRODUCT_BUNDLE_IDENTIFIER", "com.games.DFZJ.AppStore");
            proj.SetBuildProperty(target, "OTHER_LDFLAGS", "-ObjC -licucore");
            proj.SetBuildProperty(target, "PRODUCT_NAME", "⚓巅峰战舰");

            //添加依赖库
            proj.AddFrameworkToProject(target, "libiPhone-lib.a", false);
            proj.AddFrameworkToProject(target, "libc++.1.tbd", false);
            proj.AddFrameworkToProject(target, "libsqlite3.tbd", false);
            proj.AddFrameworkToProject(target, "ImageIO.framework", false);
            proj.AddFrameworkToProject(target, "WebKit.framework", false);

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

            //保存工程
            proj.WriteToFile(projPath);
        }
        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);
        }
Esempio n. 21
0
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        Debug.Log("GAv4 Unity: Post build script starts");
        if (target == BuildTarget.iOS)
        {
            // Get target for Xcode project
            string projPath = PBXProject.GetPBXProjectPath(path);
            Debug.Log("GAv4 Unity: Project path is " + projPath);

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

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

            // Add dependencies
            Debug.Log("GAv4 Unity: Adding frameworks");

            proj.AddFrameworkToProject(projectTarget, "AdSupport.framework", false);
            proj.AddFrameworkToProject(projectTarget, "CoreData.framework", false);
            proj.AddFrameworkToProject(projectTarget, "SystemConfiguration.framework", false);
            proj.AddFrameworkToProject(projectTarget, "libz.dylib", false);
            proj.AddFrameworkToProject(projectTarget, "libsqlite3.tbd", false);

            File.WriteAllText(projPath, proj.WriteToString());
        }
    }
Esempio n. 22
0
    //[PostProcessBuild(100)]
    public static void OnPostProcessBuildOld(BuildTarget target, string path)
    {
        if (target == BuildTarget.iOS)
        {
            // Get target for Xcode project
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));

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

            // Add dependencies
            proj.AddFrameworkToProject(projectTarget, "AssetsLibrary.framework", false);
            proj.AddFrameworkToProject(projectTarget, "CoreText.framework", false);
            proj.AddFrameworkToProject(projectTarget, "MobileCoreServices.framework", false);
            proj.AddFrameworkToProject(projectTarget, "QuickLook.framework", false);
            proj.AddFrameworkToProject(projectTarget, "Security.framework", false);

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

            InsertAuthCodeIntoControllerClass(path);
            InsertUILoadedCallbackIntoControllerClass(path);
        }
    }
Esempio n. 23
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));

                // old method, for Unity 2019.2 and below
                //string target = proj.TargetGuidByName("Unity-iPhone");

                // new method
                string target = proj.GetUnityFrameworkTargetGuid();

                proj.AddFrameworkToProject(target, "StoreKit.framework", false);
                proj.AddFrameworkToProject(target, "MediaPlayer.framework", false);
                File.WriteAllText(projPath, proj.WriteToString());

                /* Info.plist */

                // Read the Info.plist file
                string        plistPath = path + "/Info.plist";
                PlistDocument plist     = new PlistDocument();
                plist.ReadFromString(File.ReadAllText(plistPath));

                // Get root of plist
                PlistElementDict rootDict = plist.root;

                // add the Apple Music privacy prompt entry
                rootDict.SetString("NSAppleMusicUsageDescription", "iOS Music would like to access this device's media library to play music.");

                //Write out the Info.plist file
                plist.WriteToFile(plistPath);
            }
        }
    /// <summary>
    /// 修改Xcode工程配置
    /// </summary>
    /// <param name="path">Xcode工程根目录</param>
    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");

        // 添加系统框架.framework
        pbxProj.AddFrameworkToProject(targetGuid, "Vision.framework", false);
        pbxProj.AddFrameworkToProject(targetGuid, "CoreML.framework", false);
        pbxProj.AddFrameworksBuildPhase(targetGuid);

        /* 还是需要手动配置
         * // 添加一般文件
         *      string fileName = "MobileNet.mlmodel"; //必须输出到 Build/Library 文件夹中
         *      string srcPath = Path.Combine("Assets/Plugins", fileName);
         *      string dstPath = "Libraries/" + fileName;
         *      File.Copy(srcPath, Path.Combine(path, dstPath));
         *      //pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(fileName, dstPath, PBXSourceTree.Source)); //xcode报红
         * //pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(dstPath, fileName, PBXSourceTree.Source)); //加到了外面
         *      pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(dstPath, dstPath, PBXSourceTree.Source)); //xcode报红
         *
         *      // GoogLeNetPlaces.mlmodel
         *      string file1 = "GoogLeNetPlaces.mlmodel";
         *      string srcPath1 = Path.Combine("Assets/Plugins", file1);
         *      string dstPath1 = "Libraries/" + file1;
         * File.Copy(srcPath, Path.Combine(path, dstPath1));
         * pbxProj.AddFileToBuild(targetGuid, pbxProj.AddFile(dstPath1, dstPath1, PBXSourceTree.Source));
         */

        File.WriteAllText(projPath, pbxProj.WriteToString());
    }
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
#if UNITY_IPHONE
            // 修改xcode工程
            string     projPath = PBXProject.GetPBXProjectPath(path);
            PBXProject proj     = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));
            string target = proj.TargetGuidByName("Unity-iPhone");

            proj.AddFrameworkToProject(target, "libz.tbd", false);
            proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);

            string fileName = Application.dataPath.Replace("Assets", "iOS/XunFeiSR");
            XcodeModifyGeneral.CopyAndReplaceDirectory(fileName, Path.Combine(path, "XunFeiSR"));
            List <string> filePaths = new List <string>();
            XcodeModifyGeneral.AddFilesToBuild(ref filePaths, path, "XunFeiSR");
            foreach (var filepath in filePaths)
            {
                proj.AddFileToBuild(target, proj.AddFile(filepath, filepath));
            }

            proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/XunFeiSR");
            proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");

            proj.WriteToFile(projPath);
#endif
        }
    }
Esempio n. 26
0
    public static void LinkLibraries(string path)
    {
        // linked library
        string     projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

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

        proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");
        proj.AddFrameworkToProject(target, "CoreTelephony.framework", true);
        //proj.AddFrameworkToProject(target, "VideoToolbox.framework", true);
        proj.AddFrameworkToProject(target, "libresolv.tbd", true);
        proj.AddFrameworkToProject(target, "libiPhone-lib.a", true);
        proj.AddFrameworkToProject(target, "CoreText.framework", true);
        File.WriteAllText(projPath, proj.WriteToString());

        // permission
        string        pListPath = path + "/Info.plist";
        PlistDocument plist     = new PlistDocument();

        plist.ReadFromString(File.ReadAllText(pListPath));
        PlistElementDict rootDic = plist.root;
        //var cameraPermission = "NSCameraUsageDescription";
        //rootDic.SetString(cameraPermission, "Video need to use camera");
        var micPermission = "NSMicrophoneUsageDescription";

        rootDic.SetString(micPermission, "Voice call need to user mic");
        File.WriteAllText(pListPath, plist.WriteToString());
    }
        public static void OnPostProcessBuild(BuildTarget target, string path)
        {
                        #if UNITY_IOS
            if (shouldRun && target == BuildTarget.iOS)
            {
                // Get target for Xcode project
                string projPath = PBXProject.GetPBXProjectPath(path);

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

                // Add dependencies
                Debug.Log("KKSpeechRecognizer Unity: Adding Speech Framework");

                                #if UNITY_2019_3_OR_NEWER
                string targetName = proj.GetUnityFrameworkTargetGuid();
                proj.AddFrameworkToProject(targetName, "Speech.framework", true);
                                #else
                string targetName    = PBXProject.GetUnityTargetName();
                string projectTarget = proj.TargetGuidByName(targetName);
                proj.AddFrameworkToProject(projectTarget, "Speech.framework", true);
                                #endif

                File.WriteAllText(projPath, proj.WriteToString());
            }
                        #endif
        }
Esempio n. 28
0
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    {
        Debug.Log("[OnPostprocessBuild] target = " + target + ", pathToBuiltProject = " + pathToBuiltProject);
        if (target == BuildTarget.iOS)
        {
#if UNITY_EDITOR_OSX
            string xcodeProjectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";

            PBXProject xcodeProject = new PBXProject();
            xcodeProject.ReadFromFile(xcodeProjectPath);

            // setting bitcode to No
            string xcodeTarget = xcodeProject.TargetGuidByName("Unity-iPhone");
            xcodeProject.SetBuildProperty(xcodeTarget, "ENABLE_BITCODE", "NO");
            xcodeProject.AddBuildProperty(xcodeTarget, "OTHER_LDFLAGS", "-ObjC");
            xcodeProject.AddBuildProperty(xcodeTarget, "CLANG_ENABLE_MODULES", "YES");

            xcodeProject.AddFrameworkToProject(xcodeTarget, "AdSupport.framework", true);
            xcodeProject.AddFrameworkToProject(xcodeTarget, "iAd.framework", true);
            xcodeProject.AddFrameworkToProject(xcodeTarget, "GoogleMobileAds.framework", false);

            // Save the changes to Xcode project file.
            xcodeProject.WriteToFile(xcodeProjectPath);
#endif
        }
    }
Esempio n. 29
0
    private static void RunPostProcessTasksiOS(string projectPath)
    {
#if UNITY_IOS
        string jsonPath    = Path.Combine(Application.dataPath, "FTDSdk/IOS/FAT_sta.json");
        string jsonoutPath = projectPath + "/Libraries/FTDSdk/IOS/FAT_sta.json";

        UnityEngine.Debug.Log("FTD: IOS SDK Application.dataPath : " + Application.dataPath);
        UnityEngine.Debug.Log("FTD: IOS SDK json path : " + jsonPath);
        UnityEngine.Debug.Log("FTD: IOS SDK json copy to path : " + jsonoutPath);

        File.Copy(jsonPath, jsonoutPath, true);

        UnityEngine.Debug.Log("FTD: Starting to perform post build tasks for iOS platform.");

        string xcodeProjectPath = projectPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

        PBXProject xcodeProject = new PBXProject();
        xcodeProject.ReadFromFile(xcodeProjectPath);

        string xcodeTarget     = xcodeProject.TargetGuidByName("Unity-iPhone");
        string jsonprojectpath = "/Libraries/FTDSdk/IOS/FAT_sta.json";
        string fileGuid        = xcodeProject.AddFile(jsonoutPath, jsonprojectpath, PBXSourceTree.Source);
        xcodeProject.AddFileToBuild(xcodeTarget, fileGuid);

        // The ftd SDK needs two frameworks to be added to the project:
        // - AdSupport.framework
        // - iAd.framework
        UnityEngine.Debug.Log("FTD: Adding AdSupport.framework to Xcode project.");
        xcodeProject.AddFrameworkToProject(xcodeTarget, "AdSupport.framework", true);
        UnityEngine.Debug.Log("FTD: AdSupport.framework added successfully.");

        UnityEngine.Debug.Log("FTD: Adding iAd.framework to Xcode project.");
        xcodeProject.AddFrameworkToProject(xcodeTarget, "iAd.framework", true);
        UnityEngine.Debug.Log("FTD: iAd.framework added successfully.");

        UnityEngine.Debug.Log("FTD: Adding CoreTelephony.framework to Xcode project.");
        xcodeProject.AddFrameworkToProject(xcodeTarget, "CoreTelephony.framework", true);
        UnityEngine.Debug.Log("FTD: CoreTelephony.framework added successfully.");

        // The ftd SDK needs to have Obj-C exceptions enabled.
        // GCC_ENABLE_OBJC_EXCEPTIONS=YES

        UnityEngine.Debug.Log("FTD: Enabling Obj-C exceptions by setting GCC_ENABLE_OBJC_EXCEPTIONS value to YES.");
        xcodeProject.AddBuildProperty(xcodeTarget, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");

        UnityEngine.Debug.Log("FTD: Obj-C exceptions enabled successfully.");

        // The ftd SDK needs to have -ObjC flag set in other linker flags section because of it's categories.
        // OTHER_LDFLAGS -ObjC

        UnityEngine.Debug.Log("FTD: Adding -ObjC flag to other linker flags (OTHER_LDFLAGS).");
        xcodeProject.AddBuildProperty(xcodeTarget, "OTHER_LDFLAGS", "-ObjC");

        UnityEngine.Debug.Log("FTD: -ObjC successfully added to other linker flags.");

        // Save the changes to Xcode project file.
        xcodeProject.WriteToFile(xcodeProjectPath);
#endif
    }
Esempio n. 30
0
    private static void PatchPBXProject(string path, bool needLocationFramework, bool addPushNotificationCapability, bool useReleaseAPSEnv)
    {
        var pbxProjectPath = PBXProject.GetPBXProjectPath(path);

        var needsToWriteChanges = false;

        var pbxProject = new PBXProject();

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

        string mainTarget;
        string unityFrameworkTarget;

        var unityMainTargetGuidMethod      = pbxProject.GetType().GetMethod("GetUnityMainTargetGuid");
        var unityFrameworkTargetGuidMethod = pbxProject.GetType().GetMethod("GetUnityFrameworkTargetGuid");

        if (unityMainTargetGuidMethod != null && unityFrameworkTargetGuidMethod != null)
        {
            mainTarget           = (string)unityMainTargetGuidMethod.Invoke(pbxProject, null);
            unityFrameworkTarget = (string)unityFrameworkTargetGuidMethod.Invoke(pbxProject, null);
        }
        else
        {
            mainTarget           = pbxProject.TargetGuidByName("Unity-iPhone");
            unityFrameworkTarget = mainTarget;
        }

        // Add necessary frameworks.
        if (!pbxProject.ContainsFramework(unityFrameworkTarget, "UserNotifications.framework"))
        {
            pbxProject.AddFrameworkToProject(unityFrameworkTarget, "UserNotifications.framework", true);
            needsToWriteChanges = true;
        }
        if (needLocationFramework && !pbxProject.ContainsFramework(unityFrameworkTarget, "CoreLocation.framework"))
        {
            pbxProject.AddFrameworkToProject(unityFrameworkTarget, "CoreLocation.framework", false);
            needsToWriteChanges = true;
        }

        if (needsToWriteChanges)
        {
            File.WriteAllText(pbxProjectPath, pbxProject.WriteToString());
        }

        // Update the entitlements file.
        if (addPushNotificationCapability)
        {
            var entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS");
            if (entitlementsFileName == null)
            {
                var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
                entitlementsFileName = string.Format("{0}.entitlements", bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1));
            }

            var capManager = new ProjectCapabilityManager(pbxProjectPath, entitlementsFileName, "Unity-iPhone");
            capManager.AddPushNotifications(!useReleaseAPSEnv);
            capManager.WriteToFile();
        }
    }
Esempio n. 31
0
 static void AddFrameworks(PBXProject project, string targetGUID)
 {
     project.AddFrameworkToProject(targetGUID, "Speech.framework", false);
     //This project appears to be a default now:
     project.AddFrameworkToProject(targetGUID, "AVFoundation.framework", false);
     // Add `-ObjC` to "Other Linker Flags".
     project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
 }