iOS 查漏报错 FBRetainCycleDetector引起crash

iOS 查漏报错 FBRetainCycleDetector崩溃

pod install 遇到终端报错:
[!] An error occurred while processing the post-install hook of the Podfile.
Permission denied @ rb_sysopen - Pods/FBRetainCycleDetector/fishhook/fishhook.c

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

添加 MLeaksFinder 之后 程序会崩溃,
在Podfile文件末尾添加下面代码即可

因为MLeaksFinder 依赖 FBRetainCycleDetector,但是 FBRetainCycleDetector中的代码有需要更新的地方,所以导致了crash,可通过在Podfile中最下面添加下面代码,完美解决


require "fileutils"

post_install do |installer|
  
  ## Fix for XCode 12.5
find_and_replace("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
    "layoutCache[currentClass] = ivars;", "layoutCache[(id<NSCopying>)currentClass] = ivars;")
 
 ## Fix for XCode 13.0
    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]))) { \n             indirect_symbol_bindings[i]=cur->rebindings[j].replacement; \n         }")

end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      FileUtils.chmod("+w", name) #add
      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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容