解决办法之“Instruments: Failed to gain authorization”

1,010 阅读1分钟

背景

有时候我们想要使用Instruments分析APP的内存问题,但是会遇到如下错误“Failed to gain authorization”

image.png

问题原因

  • get-task-allow 被标记为false
    get-task-allow 这个标记用来表示是否允许其他进程attach到此APP,在Release版本中,该值被要求是false,在开发版本中,该值被要求是true的,以便APP可以被Debug。

解决方案

  • 对应用进行重签名,修改该值(Release/Debug版本均有效)
    1. 创建debug.plst,填入如下代码
    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.get-task-allow</key><true/></dict></plist>
    
    1. 签名或者重签名APP
    codesign -s - -v -f --entitlements /path/to/debug.plist /path/to/your/executable
    

参考资料

# Instruments: why? “Failed to gain authorization”
Entitlements Troubleshooting