{"id":200676,"date":"2023-08-16T13:38:29","date_gmt":"2023-08-16T05:38:29","guid":{"rendered":"https:\/\/www.idc.net\/help\/200676\/"},"modified":"2023-08-16T13:38:29","modified_gmt":"2023-08-16T05:38:29","slug":"%e4%b8%80%e4%b8%aa%e7%ae%80%e5%8d%95%e5%ae%9e%e7%94%a8%e7%9a%84android%e8%b0%83%e8%af%95%e5%ba%94%e7%94%a8%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/200676\/","title":{"rendered":"\u4e00\u4e2a\u7b80\u5355\u5b9e\u7528\u7684Android\u8c03\u8bd5\u5e94\u7528\u6280\u5de7"},"content":{"rendered":"<p>\u5728\u5e94\u7528\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u5e38\u5e38\u4f1a\u8fdb\u884c\u65e5\u5fd7\u6253\u5370\u6216\u8005debug\u8c03\u8bd5\uff0c\u4ee5\u6b64\u6765\u5206\u6790\u8fd0\u884c\u65f6\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u4fbf\u4e8e\u53d1\u73b0bug\u548c\u95ee\u9898\u3002Android Studio\u7684Debug\u529f\u80fd\u5f88\u597d\u7528\uff0c\u4f46\u662f\u6709\u65f6\u5019\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5c31\u663e\u5f97\u4e0d\u662f\u90a3\u4e48\u5feb\u6377\u548c\u4fbf\u5229\u3002<\/p>\n<p><strong>\u6bd4\u5982<\/strong><\/p>\n<ul>\n<li>\u6211\u4eec\u8c03\u8bd5\u7684\u70b9\u5728\u5e94\u7528\u4e00\u6253\u5f00\u7684\u65f6\u5019\uff0c\u5f88\u9760\u524d\uff0c\u4f8b\u5982Application\u7684onCreate\u65b9\u6cd5\u4e2d\uff0c\u4ee5\u81f3\u4e8e\u6211\u4eec\u4e0d\u80fd\u8db3\u591f\u5feb\u7684\u8bbe\u7f6e\u8fdb\u7a0b\u4e3adebug\u6a21\u5f0f<\/li>\n<li>\u867d\u7136\u4e0a\u9762\u7684\u60c5\u51b5\u53ef\u4ee5\u901a\u8fc7Android Studio\u7684debug\u8fd0\u884c\u6765\u89e3\u51b3\uff0c\u4f46\u662f\u5982\u679c\u9879\u76ee\u5f88\u5927\u7684\u8bdd\uff0c\u8fd0\u884c\u8d77\u6765\u4e5f\u4f1a\u6bd4\u8f83\u803d\u8bef\u65f6\u95f4<\/li>\n<\/ul>\n<p>\u90a3\u4e48\u600e\u4e48\u89e3\u51b3\u4e0a\u9762\u7684\u95ee\u9898\u5462\uff0c\u5176\u5b9e\u53ea\u9700\u8981\u6267\u884c\u4e00\u884c\u547d\u4ee4\u5373\u53ef<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><span><span>adb&nbsp;shell&nbsp;am&nbsp;<\/span><span>set<\/span><span>-debug-app&nbsp;-w&nbsp;com.example.jishuxiaoheiwu.appdebugsample&nbsp;<\/span><\/span><\/li>\n \n \n \n <\/ol><\/pre>\n<p><strong>\u5176\u4e2d<\/strong><\/p>\n<ul>\n<li>set-debug-app \u7528\u6765\u5e94\u7528\u4e3adebug\u6a21\u5f0f<\/li>\n<li>-w \u610f\u601d\u4e3await\uff0c\u5728\u8fdb\u7a0b\u542f\u52a8\u7684\u65f6\u5019\uff0c\u7b49\u5f85debugger\u8fdb\u884c\u8fde\u63a5<\/li>\n<li>com.example.jishuxiaoheiwu.appdebugsample \u4ee3\u8868\u60f3\u8981\u8c03\u8bd5\u7684\u5e94\u7528\u7684\u5305\u540d\u6216ApplicationId<\/li>\n<\/ul>\n<p>\u6267\u884c\u4e0a\u9762\u7684\u547d\u4ee4\uff0c\u5f53\u6211\u4eec\u518d\u6b21\u542f\u52a8\u76ee\u6807\u5e94\u7528\u65f6\uff0c\u4f1a\u5f97\u5230\u8fd9\u6837\u7684\u753b\u9762<\/p>\n<p style=\"text-align: center\">\n<p>\u7136\u540e\uff0c\u6211\u4eec\u5c31\u4f1a\u6709\u8db3\u591f\u7684\u65f6\u95f4\uff0c\u6765\u4f7f\u7528Run\u2014&gt; Attach Debugger to Android Process \u6765\u7ed1\u5b9a\u8fdb\u7a0bdebug\u3002 \u7ed1\u5b9a\u540e\u5bf9\u8bdd\u6846\u6d88\u5931\uff0c\u4e0b\u6b21\u542f\u52a8\u5c31\u662f\u6b63\u5e38\u7684\u542f\u52a8(\u6ca1\u6709\u4e0a\u9762\u7684\u5bf9\u8bdd\u6846\u4e86)<\/p>\n<p>\u90a3\u4e48\u4e00\u6b21debug\u4e0d\u4e00\u5b9a\u80fd\u89e3\u51b3\u95ee\u9898\uff0c\u591a\u6b21\u8c03\u8bd5\u5219\u5728\u6240\u96be\u514d\uff0c\u90a3\u4e48\u6bcf\u6b21\u90fd\u8981\u6267\u884c\u8fd9\u4e2a\u547d\u4ee4\u4e48?<\/p>\n<p>\u7b54\u6848\u662f\u53ef\u4ee5\uff0c\u4f46\u662f\u6709\u66f4\u597d\u7684\u65b9\u5f0f\u3002\u5373<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><span><span>adb&nbsp;shell&nbsp;am&nbsp;<\/span><span>set<\/span><span>-debug-app&nbsp;-w&nbsp;<\/span><span>--persistent&nbsp;com.example.jishuxiaoheiwu.appdebugsample<\/span><span>&nbsp;<\/span><\/span><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u548c\u4e4b\u524d\u6709\u6240\u4e0d\u540c\uff0c\u8868\u73b0\u5728\u4e00\u4e2a\u2014persistent<\/p>\n<ul>\n<li>\u2014persitent\u610f\u601d\u662f\u6301\u4e45\u7684\uff0c\u610f\u601d\u662f\u4e00\u76f4\u8bbe\u7f6e\u8fd9\u4e2a\u5e94\u7528\u4e3a\u8c03\u8bd5\u6a21\u5f0f\uff0c\u5373\u6bcf\u6b21\u5f00\u542f(\u8fdb\u7a0b\u521b\u5efa)\u90fd\u4f1a\u5f39\u51fa\u5bf9\u8bdd\u6846\uff0c\u5373\u4f7f\u5378\u8f7d\u518d\u5b89\u88c5\u6216\u8005\u66f4\u65b0\u5e94\u7528<\/li>\n<\/ul>\n<p>\u5982\u679c\u591a\u6b21debug\u5b8c\u6210\u540e\uff0c\u89e3\u51b3\u4e86\u95ee\u9898\uff0c\u60f3\u8981\u6062\u590d\u6b63\u5e38\u7684\u542f\u52a8\u4e5f\u5f88\u7b80\u5355<\/p>\n<pre>\n \n \n \n <ol>\n  \n  \n  \n  <li><span><span>adb&nbsp;shell&nbsp;am&nbsp;clear-debug-app&nbsp;<\/span><\/span><\/li>\n \n \n \n <\/ol><\/pre>\n<p>\u8fd9\u4e2a\u8c03\u8bd5\u7684\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u8282\u7701\u6211\u4eec\u5f88\u591a\u7684\u5b9d\u8d35\u65f6\u95f4\u3002\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u5404\u4f4d\u5f00\u53d1\u540c\u884c\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5f53\u4f60\u7684\u5f00\u53d1\u4e2d\u9047\u5230\u6548\u7387\u95ee\u9898\u65f6\uff0c\u4f60\u9700\u8981\u505a\u51fa\u601d\u8003\uff0c\u53d1\u89c9\u66f4\u5feb\u6377\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u800c\u4e0d\u662f\u4e3a\u4e86\u8c03\u8bd5Application\u4e2donCreate\u65b9\u6cd5\u4e2d\u7684\u4ee3\u7801\uff0c\u6bcf\u6b21\u90fd\u70b9\u51fbAndroid Studio\u7684debug\u6309\u94ae\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5e94\u7528\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u5e38\u5e38\u4f1a\u8fdb\u884c\u65e5\u5fd7\u6253\u5370\u6216\u8005debug\u8c03\u8bd5\uff0c\u4ee5\u6b64\u6765\u5206\u6790\u8fd0\u884c\u65f6\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u4fbf\u4e8e\u53d1\u73b0bug\u548c\u95ee\u9898\u3002An [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":200683,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[195111],"tags":[],"class_list":["post-200676","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/200676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=200676"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/200676\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/200683"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=200676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=200676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=200676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}