{"id":1830,"date":"2023-03-29T21:04:02","date_gmt":"2023-03-29T13:04:02","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1830"},"modified":"2023-04-22T09:19:00","modified_gmt":"2023-04-22T01:19:00","slug":"android-hot-fix-mainstream-solution","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/29\/android-hot-fix-mainstream-solution\/","title":{"rendered":"Android\u70ed\u4fee\u590d\u4e3b\u6d41\u65b9\u6848"},"content":{"rendered":"<p>\u70ed\u4fee\u590d\u65b9\u6848\u6309\u7167<strong>\u662f\u5426\u5fc5\u987b\u91cd\u542f<\/strong>\u5206\u4e3a\u4e24\u7c7b\uff1a\u91cd\u542f\u751f\u6548 \/ \u5373\u65f6\u751f\u6548\u3002\u6309\u7167<strong>\u5b9e\u73b0\u65b9\u5f0f<\/strong>\u53ef\u4ee5\u5206\u4e3a3\u7c7b\uff1aJava\u5c42\u7684\u5b9e\u73b0 \/ Native\u5c42\u7684\u5b9e\u73b0 \/ Java Native\u6df7\u5408\u5b9e\u73b0<\/p>\n<h2>\u963f\u91ccAndFix \u65b9\u6848(\u5df2\u5f03\u7528)<\/h2>\n<p><!-- more --><\/p>\n<p>AndFix \u662f \u65e0\u9700\u91cd\u542f \u7684 Native\u5c42 \u7684\u5b9e\u73b0\u3002\u4f46\u662f\uff0cAndFix\u76ee\u524d\u5df2\u7ecf3\u5e74\u591a\u6ca1\u7ef4\u62a4\u66f4\u65b0\u3002<br \/>\n\u56e0\u4e3a\u963f\u91cc\u5df2\u7ecf\u6709\u4e86\u65b0\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u4e0d\u518d\u9700\u8981\u7ef4\u62a4\u3002\u53e6\u5916\uff0c\u8fd9\u79cd\u7eafNative\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u517c\u5bb9\u6027\u5341\u5206\u582a\u5fe7\u3002<br \/>\n\u65e2\u7136\u5df2\u7ecf\u88ab\u5f03\u7528\uff0c\u4f46\u662f\u7a0d\u5fae\u4e86\u89e3\u4e00\u4e0b\u5b9e\u73b0\u65b9\u6848\u4e5f\u662f\u6ca1\u95ee\u9898\u7684\u3002<\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u6bb5\u7a0b\u5e8f\u6309\u7167<code>A=&gt;B=&gt;C<\/code>\u7684\u987a\u5e8f\u53bb\u6267\u884c\uff0c\u7136\u800c\u53d1\u73b0\u6267\u884c\u5230B\u7684\u65f6\u5019\uff0c\u5b58\u5728\u4e00\u4e2abug\uff0cAndFix\u7684\u4fee\u590d\u65b9\u5f0f\u4e3a\uff1a\u5728Native\u5c42\u6267\u884c\u5230B\u65b9\u6cd5\u7684\u65f6\u5019\uff0c\u628a<strong>\u65b9\u6cd5\u7684\u6307\u9488<\/strong>\u6307\u5411\u4e86<strong>\u8865\u4e01\u5305\u91cc\u7684B\u65b9\u6cd5<\/strong>\uff0c\u7ed5\u8fc7\u4e86<strong>\u539f\u6765\u7684B\u65b9\u6cd5<\/strong>\u3002\u4ece\u800c\u8fbe\u5230\u4e86\u4fee\u590dbug\u7684\u76ee\u7684\u3002<\/p>\n<pre><code class=\"language-java\">\/\/\u6ce8\u89e3\u8868\u793a\u8865\u4e01\u4e2d\u6b64\u65b9\u6cd5\u4f1a\u66ff\u6362apk\u4e2d\u54ea\u4e2a\u65b9\u6cd5\n@MethodReplace(clazz=&quot;cn.appblog.utils&quot;, method=&quot;test&quot;)\npublic void test() {\n    ...\n}<\/code><\/pre>\n<p>\u5728\u9700\u8981\u4fee\u590d\u7684\u65b9\u6cd5\u4e0a\u9762\uff0c\u52a0\u4e0a<code>@MethodReplace<\/code>\u6ce8\u89e3\uff0c\u7ed9\u5b9a\u53c2\u6570<code>class<\/code>\u548c<code>method<\/code>\uff0c\u8868\u793a\u8be5\u65b9\u6cd5\u66ff\u6362\u4e3a\u54ea\u4e2a\u7c7b\u7684\u54ea\u4e2a\u65b9\u6cd5\u3002<\/p>\n<p>\u7f3a\u9677\uff1a\u4fee\u590d\u7c92\u5ea6\u4e3a\uff1a<code>method<\/code>\u3002AndFix\u53ea\u80fd\u4ee5\u65b9\u6cd5\u4e3a\u7c92\u5ea6\u53bb\u4fee\u590dbug\u3002\u4f5c\u7528\u6709\u9650\uff0c\u9488\u5bf9\u5927\u8303\u56f4\u7684\u7c7b\u66ff\u6362\u548c\u8d44\u6e90\u66ff\u6362\uff0c\u90a3\u5c31\u65e0\u80fd\u4e3a\u529b\u3002<\/p>\n<h2>\u7f8e\u56e2 Robust\u65b9\u6848<\/h2>\n<p>Robust \u662f<strong>\u5373\u65f6\u751f\u6548<\/strong>\u7684<strong>Java\u5c42\u5b9e\u73b0<\/strong>\u7684\u70ed\u4fee\u590d\u5b9e\u73b0\u65b9\u6848.<\/p>\n<p>\u7f8e\u56e2\u7684Robust\u65b9\u6848\uff0c\u662f\u53c2\u8003\u4e86\u8c37\u6b4c\u7684InstantRun\u65b9\u6848\uff08\u4e4b\u524d\u5728Android Studio\u91cc\u9762\u6709\u8fd9\u4e2a\u9009\u9879\uff0c\u53ef\u4ee5\u9009\u62e9\u6253\u5f00Instant Run\u8fd0\u884capp)\u7684\u601d\u8def\u800c\u8bbe\u8ba1\u51fa\u6765\u7684\u3002<\/p>\n<p>\u5176\u4e3b\u8981\u8bbe\u8ba1\u601d\u60f3\u5c31\u662f\u4e00\u53e5\u8bdd\uff1a<strong>\u7f16\u8bd1\u6253\u5305\u65f6\uff0c\u5728\u7a0b\u5e8f\u7684\u67d0\u4e9b\u65b9\u6cd5\u91cc\u9762\uff0c\u90fd\u63d2\u5165\u4e00\u6bb5\u4ee3\u7801\uff08\u5168\u81ea\u52a8\u64cd\u4f5c\uff09<\/strong>\uff1a<\/p>\n<pre><code class=\"language-java\">if (changeQuickRedirect != null) {\n    \/\/\n    return \u4fee\u590d\u7684\u5b9e\u73b0\n}<\/code><\/pre>\n<p>\u5f53<code>changeQuickRedirect<\/code>\u4e0d\u4e3a\u7a7a\u7684\u65f6\u5019\uff0c\u8be5\u65b9\u6cd5\u5c31\u4f1a\u547d\u4e2d<code>if (changeQuickRedirect != null)<\/code>\uff0c\u4ece\u800c\u6267\u884c\u4fee\u590d\u7684\u5b9e\u73b0\u4ee3\u7801\u3002\u5f53\u4e3a\u7a7a\u7684\u65f6\u5019\uff0c\u5219\u6b63\u5e38\u6267\u884c\u539f\u903b\u8f91\u3002<\/p>\n<p>\u800c\u5e73\u65f6\u6211\u4eec\u81ea\u5df1\u7f16\u7801\uff0c\u53ea\u9700\u8981\u52a0\u4e0a\u4e00\u4e2a<code>@Modify<\/code>\u6ce8\u89e3\uff0c\u6765\u6807\u8bb0\u8fd9\u4e2a\u65b9\u6cd5\u9700\u8981\u6253\u8865\u4e01\u5305\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u63d2\u5165\u4e0a\u9762\u8fd9\u4e2a<code>if (changeQuickRedirect != null)<\/code>\u4ee3\u7801\u6bb5\u3002<\/p>\n<pre><code class=\"language-java\">\/\/\u7f16\u5199\u7684\u4ee3\u7801\n@Modify  \/\/\u6539\u52a8\u4ee3\u7801\u540e\u624b\u52a8\u6dfb\u52a0\u6ce8\u89e3\u7528\u4e8e\u8865\u4e01\u5305\u751f\u6210\npublic long getIndex() {\n    return 100;\n}<\/code><\/pre>\n<p>\uff081\uff09\u4e3a\u4ec0\u4e48Robust\u53ef\u4ee5\u5373\u65f6\u751f\u6548\uff1f<\/p>\n<p>\u4e0a\u56fe\u89e3\u6790\uff1a\u5229\u7528<code>ClassLoader<\/code>\uff0c\u5f53\u5ba2\u6237\u7aef\u624b\u673a\u6536\u5230\u8865\u4e01\u5305 <code>patch.dex<\/code>\u7684\u65f6\u5019\uff0c\u6267\u884c\u8865\u4e01\u5305\uff0c\u628a\u6307\u5b9a\u65b9\u6cd5\u7684<code>changeQuickRedirect<\/code>\u7528\u53cd\u5c04\u7684\u624b\u6bb5\u8d4b\u503c\uff0c\u8ba9\u5b83\u53d8\u6210\u975e\u7a7a\u3002\u4ece\u800c\u8ba9\u4e0b\u4e00\u6b21\u7a0b\u5e8f\u903b\u8f91\u8d70\u5230\u8fd9\u91cc\u7684\u65f6\u5019\uff0c\u8d70\u4fee\u590d\u4e4b\u540e\u7684\u903b\u8f91\u3002<\/p>\n<p>\uff082\uff09Robust\u662f\u5982\u4f55\u5c06\u8fd9\u4e48\u591a<code>if (changeQuickRedirect != null)<\/code>\u4ee3\u7801\u6bb5\u63d2\u5165\u5230\u4ee3\u7801\u903b\u8f91\u4e2d\u7684\uff1f<\/p>\n<p>\u4e0a\u56fe\u4e2d\u7684<code>if (changeQuickRedirect != null)<\/code>\u4ee3\u7801\u6bb5\uff0c\u5e76\u975e\u6211\u4eec\u624b\u52a8\u7f16\u5199\uff0c\u800c\u662f\u7531Robust\u6846\u67b6\u81ea\u52a8\u63d2\u5165\u7684<br \/>\n\u8fd9\u4e2a\u6280\u672f\u53eb\u505a<strong>\u5b57\u8282\u7801\u63d2\u6869<\/strong>\uff0c\u610f\u4e3a\uff1a\u5bf9class\u8fdb\u884c\u64cd\u4f5c\uff0c\u6309\u7167class\u6587\u4ef6\u7684\u683c\u5f0f\uff0c\u63d2\u5165\u81ea\u5df1\u60f3\u8981\u7684\u903b\u8f91<br \/>\n\u76ee\u524dRobust\u652f\u6301\u4e24\u79cd\u5b57\u8282\u7801\u63d2\u6869\u65b9\u6848<code>AspectJ<\/code>\u548c<code>Javasist<\/code><\/p>\n<h2>\u817e\u8baf Tinker dexdiff \/ DexMerge\u65b9\u6848<\/h2>\n<p>Tinker \u662f\u817e\u8baf\u81ea\u7814\u7684<strong>\u91cd\u542f\u751f\u6548<\/strong>\u7684Java\u5c42\u7684\u5b9e\u73b0<\/p>\n<p>Tinker\u57fa\u4e8e\u4e00\u4e2a\u57fa\u51c6dex\uff0c\u4ee5\u53ca\u4fee\u590dbug\u4e4b\u540e\u7684dex\uff0c\u4f7f\u7528<code>dexdiff<\/code>\u7b97\u6cd5\uff0c\u8ba1\u7b97\u51fa\u5dee\u5206\u5305dex\u3002\u7136\u540e\u628a\u5dee\u5206\u5305\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\uff0c\u5ba2\u6237\u7aef\u6536\u5230\u4e4b\u540e\uff0c\u91cd\u542f\u8fd0\u884capp\uff0c\u628a\u5dee\u5206\u5305dex\u548c\u539fdex\u8fdb\u884c\u5408\u5e76\uff0c\u5f62\u6210\u65b0\u7684dex\u3002\u7136\u540e<code>ClassLoader<\/code>\u53bb\u521b\u5efa\u7c7bclass\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u521b\u5efa\u4fee\u590dbug\u4e4b\u540e\u7684\u7c7bclass\u5bf9\u8c61\u3002\u4ece\u800c\u8fbe\u5230\u4fee\u590dbug\u7684\u76ee\u7684\u3002<\/p>\n<h3>Dexdiff\u7b97\u6cd5<\/h3>\n<p>\u4e86\u89e3\u589e\u91cf\u66f4\u65b0\u7684\u4eba\u5e94\u8be5\u77e5\u9053<code>bsdiff<\/code>\u3002<code>bsdiff<\/code>\u662f\u65e0\u89c6\u6587\u4ef6\u683c\u5f0f\uff0c\u751f\u6210\u4e24\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u5dee\u5f02\u6587\u4ef6\u3002<code>dexdiff<\/code>\u662f\u57fa\u4e8e<code>bsdiff<\/code>\uff0c\u5e76\u4e14\u8fdb\u884c\u4e86\u9488\u5bf9dex\u6587\u4ef6\u683c\u5f0f\u7684\u4f18\u5316\u3002 Tinker\u9664\u4e86\u652f\u6301Dex\u4fee\u590d\u4e4b\u5916\uff0c\u8fd8\u652f\u6301so\u4fee\u590d\uff0c\u53ea\u4e0d\u8fc7so\u7684\u5dee\u5206\u5305\uff0c\u662f\u76f4\u63a5\u4f7f\u7528\u7684<code>bsdiff<\/code>\u7b97\u6cd5\u751f\u6210\u7684\u3002<\/p>\n<h2>\u817e\u8baf QZone Muitidex\u65b9\u6848<\/h2>\n<p>Multidex\u65b9\u6848\u662f\u57fa\u4e8e<code>ClassLoader<\/code>\u7684<strong>\u7eafjava\u5b9e\u73b0<\/strong>\u7684<strong>\u91cd\u542f\u751f\u6548<\/strong>\u7684\u70ed\u4fee\u590d\u65b9\u6848<\/p>\n<p>\u539f\u7406\uff1aApk\u6253\u5305\u7684\u65f6\u5019\u53ef\u80fd\u751f\u6210\u591a\u4e2a<code>classes.dex<\/code>\u6587\u4ef6\u3002JVM\u4e2d\u7c7b\u52a0\u8f7d\u5668<code>ClassLoader<\/code>\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u4f7f\u7528\u5230\u67d0\u4e00\u4e2aClass\u7684\u65f6\u5019\uff0c\u662f\u6309\u7167<strong>\u987a\u5e8f\u67e5\u627e<\/strong>\u7684\u65b9\u5f0f\u8fdb\u884c\u7684\u3002\u4e00\u65e6\u627e\u5230\uff0c\u5c31\u4f1a<strong>\u7f13\u5b58<\/strong>\u8d77\u6765\uff0c\u4e0b\u4e00\u6b21<code>loadClass<\/code>\u5c31\u4e0d\u4f1a\u53bb\u67e5\u627e\uff0c\u800c\u662f<strong>\u76f4\u63a5\u4f7f\u7528\u7f13\u5b58<\/strong>\u4e2d\u7684\uff08\u6240\u4ee5Muitldex\u65b9\u6848<strong>\u5fc5\u987b\u91cd\u542fAPP<\/strong>\uff09\u3002\u800c\u5f53\u6211\u4eec\u628a\u8865\u4e01dex\u6587\u4ef6\u653e\u5230\u987a\u5e8f\u67e5\u627e\u7684\u6700\u524d\u9762\uff0c\u90a3\u4e48\u7c7b\u52a0\u8f7d\u5668\u67e5\u627e\u5230\u5b83\u4e4b\u540e\uff0c\u5c31\u4f1a\u76f4\u63a5\u4f7f\u7528\u3002\u539f\u6765\u7684\u540c\u6837\u7684\u7c7b\u4fbf\u5904\u4e8e\u540e\u65b9\uff0c\u4e0d\u4f1a\u518d\u751f\u6548\u3002\u7531\u6b64\uff0c\u4f7f\u7528\u8865\u4e01Class\u5b8c\u5168\u66ff\u6362\u4e86\u539fClass<\/p>\n<h2>\u65b9\u6848\u5bf9\u6bd4<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\"><\/th>\n<th style=\"text-align: center;\">Tinker<\/th>\n<th style=\"text-align: center;\">QZone<\/th>\n<th style=\"text-align: center;\">AndFix<\/th>\n<th style=\"text-align: center;\">Robust<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\u7c7b\u66ff\u6362<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">so\u66ff\u6362<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u8d44\u6e90\u66ff\u6362<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u5168\u5e73\u53f0\u652f\u6301<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u5373\u65f6\u751f\u6548<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u6027\u80fd\u635f\u8017<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<td style=\"text-align: center;\">\u8f83\u5927<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u8865\u4e01\u5305\u5927\u5c0f<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<td style=\"text-align: center;\">\u8f83\u5927<\/td>\n<td style=\"text-align: center;\">\u4e00\u822c<\/td>\n<td style=\"text-align: center;\">\u4e00\u822c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u5f00\u53d1\u900f\u660e<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u590d\u6742\u5ea6<\/td>\n<td style=\"text-align: center;\">\u8f83\u4f4e<\/td>\n<td style=\"text-align: center;\">\u8f83\u4f4e<\/td>\n<td style=\"text-align: center;\">\u590d\u6742<\/td>\n<td style=\"text-align: center;\">\u590d\u6742<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Gradle\u652f\u6301<\/td>\n<td style=\"text-align: center;\">yes<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<td style=\"text-align: center;\">no<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Rom\u4f53\u79ef<\/td>\n<td style=\"text-align: center;\">\u8f83\u5927<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<td style=\"text-align: center;\">\u8f83\u5c0f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u70ed\u4fee\u590d\u65b9\u6848\u6309\u7167\u662f\u5426\u5fc5\u987b\u91cd\u542f\u5206\u4e3a\u4e24\u7c7b\uff1a\u91cd\u542f\u751f\u6548 \/ \u5373\u65f6\u751f\u6548\u3002\u6309\u7167\u5b9e\u73b0\u65b9\u5f0f\u53ef\u4ee5\u5206\u4e3a3\u7c7b\uff1aJava\u5c42\u7684\u5b9e\u73b0 \/ N [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[311],"tags":[463,466,464,465,467],"class_list":["post-1830","post","type-post","status-publish","format-standard","hentry","category-android-advance","tag-andfix","tag-muitidex","tag-robust","tag-tinker","tag-467"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1830"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1830\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}