美文网首页
BClassStrongLayout.mm 报错 替换 脚本

BClassStrongLayout.mm 报错 替换 脚本

作者: writeSpace | 来源:发表于2021-12-18 17:37 被阅读0次
    #!/usr/bin/ruby
    
    def reference_file(installer, folder)
        path = Pathname(File.expand_path(folder, __dir__))
        installer.pods_project.main_group.new_reference(path)
    end
    
    
    def  configuration_setting(installer)  
        
        
        
        enablearray=Array.[](#需要便利修改的三方库  这里修改用来bitcode 
            'audioplayers',
            'file_picker',
            'flutter_local_notifications',
            'flutter_plugin_record',
            'flutter_boost',
            'image_picker',
            'path_provider',
            'permission_handler',
            'shared_preferences',
            'sqflite',
            'video_player',
            'wakelock',
            'webview_flutter',
                             'Flutter',
                             'auto_orientation'
            )
    
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = 11.0
              $f_index = 0
              $f_nums = enablearray.size
    #          $f_nums = 13
    
        if config.name == "Profile"
    #    优化编译速度
        config.build_settings["DEBUG_INFORMATION_FORMAT"] = "dwarf"#不生成DSYM文件 
        config.build_settings["ONLY_ACTIVE_ARCH"] = 'YES'#只生成编译的报
    #    优化编译速度
    
    
        end
    
              while $f_index < $f_nums do
                if target.name == enablearray[$f_index]
                  config.build_settings["ENABLE_BITCODE"] = false
                end
                $f_index += 1
              end
    
    
              end
            end
            installer.pods_project.build_configurations.each do |config|
              config.build_settings["EXCLUDED_ARCHS[sdk=ç*]"] = "arm64"#支持arm64 架构
              
    
            end
    
    end
    
    def find_and_replace(dir, findstr, replacestr, mark)#代码替换方法
    # 判断文件是否存在
    if File.exist?(dir) == false
        return   puts "不存在" + dir
    end
    
    # 判断文件是否有写入权限
       p=File.writable?( dir )
       if p == false #没有则赋予权限
        File.chmod(0644, dir)
       end
    
            Dir[dir].each do |name|
                text = File.read(name)
    # 判断内容是否有标记  有标记则代表更换过
                if text.include?mark
                    puts "包含"
                else
                    replace = text.gsub(findstr,replacestr)
                    puts "replace"
                    puts replace
                    if text != replace #是否相等 不等在替换
                        File.open(name, "w+") { |file| file.puts replace }
                        puts "Fix: " + name
                    STDOUT.flush
                    else
                        puts "一样"
                    end
                end
            end
            Dir[dir + '*/'].each(&method(:find_and_replace))
    end
    

    Podfile 中调用姿势

     
      post_install do |installer|
    
        
        reference_file(installer, 'BLHelp.rb')
        configuration_setting(installer)
        ## Fix for XCode 12.5 适配
        find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm","layoutCache[currentClass] = ivars;", "layoutCache[(id<NSCopying>)currentClass] = ivars;//mark","//mark")
        #    替换mokneyking代码
        find_and_replace("Pods/MonkeyKing/Sources/MonkeyKing/MonkeyKing+Program.swift","URLQueryItem(name: \"path\", value: path),","URLQueryItem(name: \"path\", value: p),//pmark","//pmark")
        find_and_replace("Pods/MonkeyKing/Sources/MonkeyKing/MonkeyKing+Program.swift","case .miniApp(let username, let path, let type):","case .miniApp(let username, let path, let type):\n var p:String = path! \n if (p ).contains(\"?\") { \n let range = p.range(of: \"?\")! \n p.insert(contentsOf: \"source=app&\", at: \ p.index(after: range.lowerBound)) \n }else{ \n p = (path ?? \"\") + \"?source=app\" \n }//alert","//alert");
      end
    

    相关文章

      网友评论

          本文标题:BClassStrongLayout.mm 报错 替换 脚本

          本文链接:https://www.haomeiwen.com/subject/qbpgfrtx.html