正确接入MLeaksFinder,一定能正常使用的

331 阅读1分钟

负责MLeaksFinder的团队已经在git上更新了,将停止对该sdk的维护。所以接入就是各种问题

直奔正题,实现正确接入MLeaksFinder,还能正常的跑起来

1:添加正确的版本号

pod 'MLeaksFinder','1.0.0', :configurations => ['Debug']

pod 'FBRetainCycleDetector','0.1.4'

切记FBRetainCycleDetector的版本号一定要是0.1.4,不然我都不保证能正常运行

2:添加ruby脚本替换


post_install do |installer|
  
  installer.pods_project.targets.each do |target|

    target.build_configurations.each do |config|

      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'

      find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",

                       "layoutCache[currentClass] = ivars;", "layoutCache[(id<NSCopying>)currentClass] = ivars;")

      find_and_replace("Pods/FBRetainCycleDetector/fishhook/fishhook.c",

                                        "indirect_symbol_bindings[i] = cur->rebindings[j].replacement;", "if (i < (sizeof(indirect_symbol_bindings) / sizeof(indirect_symbol_bindings[0]))){\

                                        indirect_symbol_bindings[i] = cur -> rebindings[j].replacement;\

                                        }")

  


    end

  end

  

end


def find_and_replace(dir, findstr, replacestr)

  Dir[dir].each do |name|

      text = File.read(name)

      replace = text.gsub(findstr,replacestr)

      if text != replace

          puts "Fix: " + name

          File.open(name, "w") { |file| file.puts replace }

          STDOUT.flush

      end

  end

  Dir[dir + '*/'].each(&method(:find_and_replace))

end

3:执行 pod install 校验有没有成功

Fix: Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm
Fix: Pods/FBRetainCycleDetector/fishhook/fishhook.c

能看到这两行,就说明基本ok,剩下的就是编译成功

打完收工,简单记录一下