• iOS——xcodeproj脚本


    Ruby脚本设置Xcode

    xcodeproj脚本常用操作:

    require 'xcodeproj'
    
    # 移除Group下所有
    def removeBuildPhaseFilesRecursively(aTarget, aGroup)
        aGroup.files.each do |file|
            if file.real_path.to_s.end_with?(".m", ".mm", ".cpp") then
                aTarget.source_build_phase.remove_file_reference(file)
            elsif file.real_path.to_s.end_with?(".plist") then
                aTarget.resources_build_phase.remove_file_reference(file)
            end
        end
    
        aGroup.groups.each do |group|
            removeBuildPhaseFilesRecursively(aTarget, group)
        end
    end
    
    # 添加文件
    def addfiles (direc, current_group, main_target)
        Dir.glob(direc) do |item|
            next if item == '.' or item == '.DS_Store'
    
                    if File.directory?(item)
                new_folder = File.basename(item)
                created_group = current_group.new_group(new_folder)
                addfiles("#{item}/*", created_group, main_target)
            else 
                i = current_group.new_file(item)
                if item.include? ".m" or item.include? ".mm" or item.include? ".swift"
                    main_target.add_file_references([i])
                end
            end
        end
    end
    
    # 设置build setting
    def buildset(project)
        # 遍历配置
        project.targets[0].build_configurations.each do |config|
            puts config.name   # Debug / Release
            #获得build settings
            build_settings = config.build_settings
            #build_settings是一个哈希,里面是一个个配置
            # build_settings.each do |key,value|
            #     # print key, " == ", value, "
    "
            #     # 可在这里进行设置证书等操作,常用的如下:
            # end
    
            build_settings["ENABLE_BITCODE"] = "NO"                 # 快手广告取消设置bitcode
    
        end
    end
    
    # 脚本入口
    path = File.join(File.dirname(__FILE__), "./Unity-iPhone.xcodeproj")
    project = Xcodeproj::Project.open(path)
    
    project.targets.each do |target|
        puts target.name
    end
    
    # 获取以项目命名的Target
    target = project.targets.first
    
    unityClassGroup = project.main_group.find_subpath(File.join('Classes'), true)
    
    unityClassGroup.set_source_tree('SOURCE_ROOT')
    
    # if !unityClassGroup.empty? then
    #     removeBuildPhaseFilesRecursively(target, unityClassGroup)
    #     unityClassGroup.clear()
    # end
    
    # 要复制的文件夹
    filesDic = '/Users/UserName/Desktop/ExampleFolder'
    
    addfiles("#{filesDic}/*", unityClassGroup, target)
    
    buildset(project)
    
    project.save
    
    

    执行脚本:

    
    ruby xcodeproj.rb
    
    
  • 相关阅读:
    关于证书
    title向左_右滚动效果
    js标题滚动效果
    js小结
    javascript数组以及对象
    javascript数据类型转换
    javascript变量作用域
    sqlldr
    java 配置文件读取
    hbase 协处理器
  • 原文地址:https://www.cnblogs.com/sylvan/p/15314051.html
Copyright © 2020-2023  润新知